Search in sources :

Example 31 with Player

use of org.powerbot.script.rt4.Player in project ExoPlayer by google.

the class TestPlayerRunHelper method runUntilPositionDiscontinuity.

/**
 * Runs tasks of the main {@link Looper} until {@link
 * Player.Listener#onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)} is
 * called with the specified {@link Player.DiscontinuityReason} or a playback error occurs.
 *
 * <p>If a playback error occurs it will be thrown wrapped in an {@link IllegalStateException}.
 *
 * @param player The {@link Player}.
 * @param expectedReason The expected {@link Player.DiscontinuityReason}.
 * @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
 *     exceeded.
 */
public static void runUntilPositionDiscontinuity(Player player, @Player.DiscontinuityReason int expectedReason) throws TimeoutException {
    verifyMainTestThread(player);
    AtomicBoolean receivedCallback = new AtomicBoolean(false);
    Player.Listener listener = new Player.Listener() {

        @Override
        public void onPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, int reason) {
            if (reason == expectedReason) {
                receivedCallback.set(true);
            }
        }
    };
    player.addListener(listener);
    runMainLooperUntil(() -> receivedCallback.get() || player.getPlayerError() != null);
    player.removeListener(listener);
    if (player.getPlayerError() != null) {
        throw new IllegalStateException(player.getPlayerError());
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Player(com.google.android.exoplayer2.Player) ExoPlayer(com.google.android.exoplayer2.ExoPlayer)

Example 32 with Player

use of org.powerbot.script.rt4.Player in project ExoPlayer by google.

the class PlaybackStatsListenerTest method playerRelease_callsAllPendingCallbacks.

@Test
public void playerRelease_callsAllPendingCallbacks() throws Exception {
    PlaybackStatsListener.Callback callback = mock(PlaybackStatsListener.Callback.class);
    PlaybackStatsListener playbackStatsListener = new PlaybackStatsListener(/* keepHistory= */
    true, callback);
    player.addAnalyticsListener(playbackStatsListener);
    MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(/* windowCount= */
    1));
    player.setMediaSources(ImmutableList.of(mediaSource, mediaSource));
    player.prepare();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
    // Play close to the end of the first item to ensure the second session is already created, but
    // the first one isn't finished yet.
    TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */
    0, /* positionMs= */
    player.getDuration());
    runUntilPendingCommandsAreFullyHandled(player);
    player.release();
    ShadowLooper.idleMainLooper();
    ArgumentCaptor<AnalyticsListener.EventTime> eventTimeCaptor = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(callback, times(2)).onPlaybackStatsReady(eventTimeCaptor.capture(), any());
    assertThat(eventTimeCaptor.getAllValues().stream().map(eventTime -> eventTime.windowIndex).collect(Collectors.toList())).containsExactly(0, 1);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled) RunWith(org.junit.runner.RunWith) PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) Player(com.google.android.exoplayer2.Player) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) After(org.junit.After) MediaSource(com.google.android.exoplayer2.source.MediaSource) Before(org.junit.Before) MediaItem(com.google.android.exoplayer2.MediaItem) ShadowLooper(org.robolectric.shadows.ShadowLooper) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) TestPlayerRunHelper(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) Mockito.never(org.mockito.Mockito.never) Nullable(androidx.annotation.Nullable) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Mockito.mock(org.mockito.Mockito.mock) MediaSource(com.google.android.exoplayer2.source.MediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Test(org.junit.Test)

Example 33 with Player

use of org.powerbot.script.rt4.Player in project ExoPlayer by google.

the class PlaybackStatsListenerTest method playlistClear_callsAllPendingCallbacks.

@Test
public void playlistClear_callsAllPendingCallbacks() throws Exception {
    PlaybackStatsListener.Callback callback = mock(PlaybackStatsListener.Callback.class);
    PlaybackStatsListener playbackStatsListener = new PlaybackStatsListener(/* keepHistory= */
    true, callback);
    player.addAnalyticsListener(playbackStatsListener);
    MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(/* windowCount= */
    1));
    player.setMediaSources(ImmutableList.of(mediaSource, mediaSource));
    player.prepare();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
    // Play close to the end of the first item to ensure the second session is already created, but
    // the first one isn't finished yet.
    TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */
    0, /* positionMs= */
    player.getDuration());
    runUntilPendingCommandsAreFullyHandled(player);
    player.clearMediaItems();
    ShadowLooper.idleMainLooper();
    ArgumentCaptor<AnalyticsListener.EventTime> eventTimeCaptor = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(callback, times(2)).onPlaybackStatsReady(eventTimeCaptor.capture(), any());
    assertThat(eventTimeCaptor.getAllValues().stream().map(eventTime -> eventTime.windowIndex).collect(Collectors.toList())).containsExactly(0, 1);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled) RunWith(org.junit.runner.RunWith) PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) Player(com.google.android.exoplayer2.Player) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) After(org.junit.After) MediaSource(com.google.android.exoplayer2.source.MediaSource) Before(org.junit.Before) MediaItem(com.google.android.exoplayer2.MediaItem) ShadowLooper(org.robolectric.shadows.ShadowLooper) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) TestPlayerRunHelper(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) Mockito.never(org.mockito.Mockito.never) Nullable(androidx.annotation.Nullable) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Mockito.mock(org.mockito.Mockito.mock) MediaSource(com.google.android.exoplayer2.source.MediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Test(org.junit.Test)

Example 34 with Player

use of org.powerbot.script.rt4.Player in project ExoPlayer by google.

the class CastPlayerTest method autoTransition_notifiesPositionDiscontinuity.

@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void autoTransition_notifiesPositionDiscontinuity() {
    int[] mediaQueueItemIds = new int[] { 1, 2 };
    int[] streamTypes = { MediaInfo.STREAM_TYPE_BUFFERED, MediaInfo.STREAM_TYPE_BUFFERED };
    long[] durationsFirstMs = { 12500, C.TIME_UNSET };
    // When the remote Cast player transitions to an item that wasn't played before, the media state
    // delivers the duration for that media item which updates the timeline accordingly.
    long[] durationsSecondMs = { 12500, 22000 };
    List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
    castPlayer.addMediaItems(mediaItems);
    updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
    1, /* streamTypes= */
    streamTypes, /* durationsMs= */
    durationsFirstMs, /* positionMs= */
    C.TIME_UNSET);
    updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
    2, /* streamTypes= */
    streamTypes, /* durationsMs= */
    durationsSecondMs, /* positionMs= */
    C.TIME_UNSET);
    Player.PositionInfo oldPosition = new Player.PositionInfo(/* windowUid= */
    1, /* windowIndex= */
    0, new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build(), /* periodUid= */
    1, /* periodIndex= */
    0, /* positionMs= */
    12500, /* contentPositionMs= */
    12500, /* adGroupIndex= */
    C.INDEX_UNSET, /* adIndexInAdGroup= */
    C.INDEX_UNSET);
    Player.PositionInfo newPosition = new Player.PositionInfo(/* windowUid= */
    2, /* windowIndex= */
    1, new MediaItem.Builder().setUri(Uri.EMPTY).setTag(2).build(), /* periodUid= */
    2, /* periodIndex= */
    1, /* positionMs= */
    0, /* contentPositionMs= */
    0, /* adGroupIndex= */
    C.INDEX_UNSET, /* adIndexInAdGroup= */
    C.INDEX_UNSET);
    InOrder inOrder = Mockito.inOrder(mockListener);
    inOrder.verify(mockListener).onPositionDiscontinuity(eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    inOrder.verify(mockListener).onPositionDiscontinuity(eq(oldPosition), eq(newPosition), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(anyInt());
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
}
Also used : Player(com.google.android.exoplayer2.Player) InOrder(org.mockito.InOrder) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 35 with Player

use of org.powerbot.script.rt4.Player in project ExoPlayer by google.

the class AdTagLoader method onTimelineChanged.

// Player.Listener implementation.
@Override
public void onTimelineChanged(Timeline timeline, @Player.TimelineChangeReason int reason) {
    if (timeline.isEmpty()) {
        // The player is being reset or contains no media.
        return;
    }
    this.timeline = timeline;
    Player player = checkNotNull(this.player);
    long contentDurationUs = timeline.getPeriod(player.getCurrentPeriodIndex(), period).durationUs;
    contentDurationMs = Util.usToMs(contentDurationUs);
    if (contentDurationUs != adPlaybackState.contentDurationUs) {
        adPlaybackState = adPlaybackState.withContentDurationUs(contentDurationUs);
        updateAdPlaybackState();
    }
    long contentPositionMs = getContentPeriodPositionMs(player, timeline, period);
    maybeInitializeAdsManager(contentPositionMs, contentDurationMs);
    handleTimelineOrPositionChanged();
}
Also used : Player(com.google.android.exoplayer2.Player) VideoAdPlayer(com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer)

Aggregations

Player (com.google.android.exoplayer2.Player)39 Nullable (androidx.annotation.Nullable)25 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)14 MediaItem (com.google.android.exoplayer2.MediaItem)11 Test (org.junit.Test)10 VideoAdPlayer (com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer)8 Timeline (com.google.android.exoplayer2.Timeline)8 Context (android.content.Context)6 ApplicationProvider (androidx.test.core.app.ApplicationProvider)6 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)6 ForwardingPlayer (com.google.android.exoplayer2.ForwardingPlayer)6 TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled (com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled)6 Tile (org.powerbot.script.Tile)6 SuppressLint (android.annotation.SuppressLint)5 Pair (android.util.Pair)5 Surface (android.view.Surface)5 SurfaceTexture (android.graphics.SurfaceTexture)4 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)4 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)4 PlaybackOutput (com.google.android.exoplayer2.robolectric.PlaybackOutput)4