Search in sources :

Example 26 with PlayerRunnable

use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.

the class ExoPlayerTest method seekAfterPlaybackError.

@Test
public void seekAfterPlaybackError() throws Exception {
    final Timeline timeline = new FakeTimeline(/* windowCount= */
    2);
    final long[] positionHolder = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
    final int[] mediaItemIndexHolder = { C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET };
    final FakeMediaSource firstMediaSource = new FakeMediaSource(timeline);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).playUntilPosition(/* mediaItemIndex= */
    1, /* positionMs= */
    500).throwPlaybackException(ExoPlaybackException.createForSource(new IOException(), PlaybackException.ERROR_CODE_IO_UNSPECIFIED)).waitForPlaybackState(Player.STATE_IDLE).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Position while in error state
            positionHolder[0] = player.getCurrentPosition();
            mediaItemIndexHolder[0] = player.getCurrentMediaItemIndex();
        }
    }).seek(/* mediaItemIndex= */
    0, /* positionMs= */
    C.TIME_UNSET).waitForPendingPlayerCommands().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Position while in error state
            positionHolder[1] = player.getCurrentPosition();
            mediaItemIndexHolder[1] = player.getCurrentMediaItemIndex();
        }
    }).prepare().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Position after prepare.
            positionHolder[2] = player.getCurrentPosition();
            mediaItemIndexHolder[2] = player.getCurrentMediaItemIndex();
        }
    }).play().build();
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(firstMediaSource).setActionSchedule(actionSchedule).build();
    assertThrows(ExoPlaybackException.class, () -> testRunner.start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS));
    assertThat(positionHolder[0]).isAtLeast(500L);
    assertThat(positionHolder[1]).isEqualTo(0L);
    assertThat(positionHolder[2]).isEqualTo(0L);
    assertThat(mediaItemIndexHolder[0]).isEqualTo(1);
    assertThat(mediaItemIndexHolder[1]).isEqualTo(0);
    assertThat(mediaItemIndexHolder[2]).isEqualTo(0);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) IOException(java.io.IOException) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 27 with PlayerRunnable

use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.

the class ExoPlayerTest method setMediaSources_whenPrepared_correctMaskingPlaybackState.

@Test
public void setMediaSources_whenPrepared_correctMaskingPlaybackState() throws Exception {
    Timeline firstTimeline = new FakeTimeline(/* windowCount= */
    1, 1L);
    MediaSource firstMediaSource = new FakeMediaSource(firstTimeline);
    Timeline secondTimeline = new FakeTimeline(/* windowCount= */
    1, 2L);
    MediaSource secondMediaSource = new FakeMediaSource(secondTimeline);
    final int[] maskingPlaybackStates = new int[4];
    Arrays.fill(maskingPlaybackStates, C.INDEX_UNSET);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Set empty media item with an implicit seek to current position.
            player.setMediaSource(new ConcatenatingMediaSource(), /* resetPosition= */
            false);
            // Expect masking state is ended,
            maskingPlaybackStates[0] = player.getPlaybackState();
        }
    }).waitForPlaybackState(Player.STATE_ENDED).setMediaSources(/* mediaItemIndex= */
    0, /* positionMs= */
    C.TIME_UNSET, firstMediaSource).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Set empty media item with an explicit seek.
            player.setMediaSource(new ConcatenatingMediaSource(), /* startPositionMs= */
            C.TIME_UNSET);
            // Expect masking state is ended,
            maskingPlaybackStates[1] = player.getPlaybackState();
        }
    }).waitForPlaybackState(Player.STATE_ENDED).setMediaSources(/* mediaItemIndex= */
    0, /* positionMs= */
    C.TIME_UNSET, firstMediaSource).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Set media item with an explicit seek.
            player.setMediaSource(secondMediaSource, /* startPositionMs= */
            C.TIME_UNSET);
            // Expect masking state is buffering,
            maskingPlaybackStates[2] = player.getPlaybackState();
        }
    }).waitForPlaybackState(Player.STATE_READY).setMediaSources(/* mediaItemIndex= */
    0, /* positionMs= */
    C.TIME_UNSET, firstMediaSource).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Set media item with an implicit seek to the current position.
            player.setMediaSource(secondMediaSource, /* resetPosition= */
            false);
            // Expect masking state is buffering,
            maskingPlaybackStates[3] = player.getPlaybackState();
        }
    }).play().waitForPlaybackState(Player.STATE_READY).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setExpectedPlayerEndedCount(/* expectedPlayerEndedCount= */
    3).setMediaSources(firstMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    // Expect reset of masking to first media item.
    exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_BUFFERING, // Ready after initial prepare.
    Player.STATE_READY, // Ended after setting empty source without seek.
    Player.STATE_ENDED, Player.STATE_BUFFERING, // Ready again after re-setting source.
    Player.STATE_READY, // Ended after setting empty source with seek.
    Player.STATE_ENDED, Player.STATE_BUFFERING, // Ready again after re-setting source.
    Player.STATE_READY, Player.STATE_BUFFERING, // Ready after setting media item with seek.
    Player.STATE_READY, Player.STATE_BUFFERING, // Ready again after re-setting source.
    Player.STATE_READY, // Play.
    Player.STATE_BUFFERING, // Ready after setting media item without seek.
    Player.STATE_READY, Player.STATE_ENDED);
    assertArrayEquals(new int[] { Player.STATE_ENDED, Player.STATE_ENDED, Player.STATE_BUFFERING, Player.STATE_BUFFERING }, maskingPlaybackStates);
    exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, // Initial source.
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, // Empty source.
    Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, // Reset source.
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, // Empty source.
    Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, // Reset source.
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, // Set source with seek.
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, // Reset source.
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, // Set source without seek.
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
Also used : NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 28 with PlayerRunnable

use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.

the class DefaultAnalyticsCollectorTest method adPlayback.

@Test
public void adPlayback() throws Exception {
    long contentDurationsUs = 11 * C.MICROS_PER_SECOND;
    long windowOffsetInFirstPeriodUs = TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
    AtomicReference<AdPlaybackState> adPlaybackState = new AtomicReference<>(FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    1, /* adGroupTimesUs...= */
    windowOffsetInFirstPeriodUs, windowOffsetInFirstPeriodUs + 5 * C.MICROS_PER_SECOND, C.TIME_END_OF_SOURCE));
    AtomicInteger playedAdCount = new AtomicInteger(0);
    Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, contentDurationsUs, adPlaybackState.get()));
    FakeMediaSource fakeMediaSource = new FakeMediaSource(adTimeline, DrmSessionManager.DRM_UNSUPPORTED, (unusedFormat, mediaPeriodId) -> {
        if (mediaPeriodId.isAd()) {
            return ImmutableList.of(oneByteSample(/* timeUs= */
            0, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM);
        } else {
            // postroll.
            return ImmutableList.of(oneByteSample(windowOffsetInFirstPeriodUs + C.MICROS_PER_SECOND, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(windowOffsetInFirstPeriodUs + 6 * C.MICROS_PER_SECOND, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(windowOffsetInFirstPeriodUs + contentDurationsUs, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM);
        }
    }, ExoPlayerTestRunner.VIDEO_FORMAT);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            player.addListener(new Player.Listener() {

                @Override
                public void onPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, @Player.DiscontinuityReason int reason) {
                    if (!player.isPlayingAd() && reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
                        // Finished playing ad. Marked as played.
                        adPlaybackState.set(adPlaybackState.get().withPlayedAd(/* adGroupIndex= */
                        playedAdCount.getAndIncrement(), /* adIndexInAdGroup= */
                        0));
                        fakeMediaSource.setNewSourceInfo(new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
                        1, /* id= */
                        0, /* isSeekable= */
                        true, /* isDynamic= */
                        false, contentDurationsUs, adPlaybackState.get())), /* sendManifestLoadEvents= */
                        false);
                    }
                }
            });
        }
    }).pause().waitForIsLoading(true).waitForIsLoading(false).waitForPlaybackState(Player.STATE_READY).playUntilPosition(/* mediaItemIndex= */
    0, /* positionMs= */
    3_000).waitForPendingPlayerCommands().playUntilPosition(/* mediaItemIndex= */
    0, /* positionMs= */
    8_000).waitForPendingPlayerCommands().play().waitForPlaybackState(Player.STATE_ENDED).waitForTimelineChanged().build();
    TestAnalyticsListener listener = runAnalyticsTest(fakeMediaSource, actionSchedule);
    Object periodUid = listener.lastReportedTimeline.getUidOfPeriod(/* periodIndex= */
    0);
    EventWindowAndPeriodId prerollAd = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    0));
    EventWindowAndPeriodId midrollAd = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* adGroupIndex= */
    1, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    0));
    EventWindowAndPeriodId postrollAd = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* adGroupIndex= */
    2, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    0));
    EventWindowAndPeriodId contentAfterPreroll = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    1));
    EventWindowAndPeriodId contentAfterMidroll = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    2));
    EventWindowAndPeriodId contentAfterPostroll = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    C.INDEX_UNSET));
    assertThat(listener.getEvents(EVENT_PLAYER_STATE_CHANGED)).containsExactly(WINDOW_0, /* setPlayWhenReady=true */
    WINDOW_0, /* setPlayWhenReady=false */
    WINDOW_0, /* BUFFERING */
    prerollAd, /* READY */
    prerollAd, /* setPlayWhenReady=true */
    contentAfterPreroll, /* setPlayWhenReady=false */
    contentAfterPreroll, /* setPlayWhenReady=true */
    contentAfterMidroll, /* setPlayWhenReady=false */
    contentAfterMidroll, /* setPlayWhenReady=true */
    contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)).containsExactly(WINDOW_0, /* PLAYLIST_CHANGED */
    prerollAd, /* SOURCE_UPDATE (initial) */
    contentAfterPreroll, /* SOURCE_UPDATE (played preroll) */
    contentAfterMidroll, /* SOURCE_UPDATE (played midroll) */
    contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_POSITION_DISCONTINUITY)).containsExactly(contentAfterPreroll, midrollAd, contentAfterMidroll, postrollAd, contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_IS_LOADING_CHANGED)).containsExactly(prerollAd, prerollAd).inOrder();
    assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(prerollAd, contentAfterPreroll, midrollAd, contentAfterMidroll, postrollAd, contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_LOAD_STARTED)).containsExactly(WINDOW_0, /* content manifest */
    prerollAd, contentAfterPreroll, midrollAd, contentAfterMidroll, postrollAd, contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)).containsExactly(WINDOW_0, /* content manifest */
    prerollAd, contentAfterPreroll, midrollAd, contentAfterMidroll, postrollAd, contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)).containsExactly(prerollAd, contentAfterPreroll, midrollAd, contentAfterMidroll, postrollAd, contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_ENABLED)).containsExactly(prerollAd);
    assertThat(listener.getEvents(EVENT_DECODER_INIT)).containsExactly(prerollAd, contentAfterPreroll, midrollAd, contentAfterMidroll, postrollAd, contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_FORMAT_CHANGED)).containsExactly(prerollAd, contentAfterPreroll, midrollAd, contentAfterMidroll, postrollAd, contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_ENABLED)).containsExactly(prerollAd);
    assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(prerollAd, contentAfterPreroll, midrollAd, contentAfterMidroll, postrollAd, contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(prerollAd, contentAfterPreroll, midrollAd, contentAfterMidroll, postrollAd, contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(contentAfterPreroll, contentAfterMidroll, contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(prerollAd, contentAfterPreroll, midrollAd, contentAfterMidroll, postrollAd, contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(prerollAd, contentAfterPreroll, midrollAd, contentAfterMidroll, postrollAd, contentAfterPostroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).containsExactly(contentAfterPreroll, contentAfterMidroll, contentAfterPostroll).inOrder();
    listener.assertNoMoreEvents();
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 29 with PlayerRunnable

use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.

the class ExoPlayerTest method seekTo_mediaItemIndexIsReset.

@Test
public void seekTo_mediaItemIndexIsReset() throws Exception {
    FakeTimeline fakeTimeline = new FakeTimeline();
    FakeMediaSource mediaSource = new FakeMediaSource(fakeTimeline);
    final int[] mediaItemIndex = { C.INDEX_UNSET };
    final long[] positionMs = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
    final long[] bufferedPositions = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().seek(/* mediaItemIndex= */
    1, /* positionMs= */
    C.TIME_UNSET).playUntilPosition(/* mediaItemIndex= */
    1, /* positionMs= */
    3000).pause().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            positionMs[0] = player.getCurrentPosition();
            bufferedPositions[0] = player.getBufferedPosition();
            player.setMediaSource(mediaSource, /* startPositionMs= */
            7000);
            player.prepare();
            positionMs[1] = player.getCurrentPosition();
            bufferedPositions[1] = player.getBufferedPosition();
        }
    }).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            mediaItemIndex[0] = player.getCurrentMediaItemIndex();
            positionMs[2] = player.getCurrentPosition();
            bufferedPositions[2] = player.getBufferedPosition();
        }
    }).build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource, mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS);
    assertThat(mediaItemIndex[0]).isEqualTo(0);
    assertThat(positionMs[0]).isAtLeast(3000);
    assertThat(positionMs[1]).isEqualTo(7000);
    assertThat(positionMs[2]).isEqualTo(7000);
    assertThat(bufferedPositions[0]).isAtLeast(3000);
    assertThat(bufferedPositions[1]).isEqualTo(7000);
    assertThat(bufferedPositions[2]).isEqualTo(fakeTimeline.getWindow(0, new Window()).getDurationMs());
}
Also used : Window(com.google.android.exoplayer2.Timeline.Window) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 30 with PlayerRunnable

use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.

the class ExoPlayerTest method clearMediaItems_correctMasking.

@Test
public void clearMediaItems_correctMasking() throws Exception {
    final int[] currentMediaItemIndices = { C.INDEX_UNSET, C.INDEX_UNSET };
    final int[] maskingPlaybackState = { C.INDEX_UNSET };
    final long[] currentPosition = { C.TIME_UNSET, C.TIME_UNSET };
    final long[] bufferedPosition = { C.TIME_UNSET, C.TIME_UNSET };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).playUntilPosition(/* mediaItemIndex= */
    1, /* positionMs= */
    150).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
            currentPosition[0] = player.getCurrentPosition();
            bufferedPosition[0] = player.getBufferedPosition();
            player.clearMediaItems();
            currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
            currentPosition[1] = player.getCurrentPosition();
            bufferedPosition[1] = player.getBufferedPosition();
            maskingPlaybackState[0] = player.getPlaybackState();
        }
    }).build();
    new ExoPlayerTestRunner.Builder(context).initialSeek(/* mediaItemIndex= */
    1, /* positionMs= */
    C.TIME_UNSET).setMediaSources(new FakeMediaSource(), new FakeMediaSource()).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertArrayEquals(new int[] { 1, 0 }, currentMediaItemIndices);
    assertThat(currentPosition[0]).isAtLeast(150);
    assertThat(currentPosition[1]).isEqualTo(0);
    assertThat(bufferedPosition[0]).isAtLeast(150);
    assertThat(bufferedPosition[1]).isEqualTo(0);
    assertArrayEquals(new int[] { 1, 0 }, currentMediaItemIndices);
    assertArrayEquals(new int[] { Player.STATE_ENDED }, maskingPlaybackState);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Aggregations

PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)93 Test (org.junit.Test)91 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)76 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)74 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)56 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)51 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)43 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)34 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)28 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)28 MediaSource (com.google.android.exoplayer2.source.MediaSource)21 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)20 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)20 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)20 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)20 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)20 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)18 AtomicLong (java.util.concurrent.atomic.AtomicLong)15 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11