Search in sources :

Example 1 with ExoPlayerTestRunner

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

the class ExoPlayerTest method dynamicTimelineChangeReason.

@Test
public void dynamicTimelineChangeReason() throws Exception {
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(false, false, 100000));
    final Timeline timeline2 = new FakeTimeline(new TimelineWindowDefinition(false, false, 20000));
    final FakeMediaSource mediaSource = new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForTimelineChanged(timeline, /* expectedReason */
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).executeRunnable(() -> mediaSource.setNewSourceInfo(timeline2)).waitForTimelineChanged(timeline2, /* expectedReason */
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).play().build();
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    testRunner.assertTimelinesSame(placeholderTimeline, timeline, timeline2);
    testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, 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) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 2 with ExoPlayerTestRunner

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

the class ExoPlayerTest method delegatingMediaSourceApproach.

@Test
public void delegatingMediaSourceApproach() throws Exception {
    Timeline fakeTimeline = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    10_000_000));
    final ConcatenatingMediaSource underlyingSource = new ConcatenatingMediaSource();
    CompositeMediaSource<Void> delegatingMediaSource = new CompositeMediaSource<Void>() {

        @Override
        public void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
            super.prepareSourceInternal(mediaTransferListener);
            underlyingSource.addMediaSource(new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT));
            underlyingSource.addMediaSource(new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT));
            prepareChildSource(null, underlyingSource);
        }

        @Override
        public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
            return underlyingSource.createPeriod(id, allocator, startPositionUs);
        }

        @Override
        public void releasePeriod(MediaPeriod mediaPeriod) {
            underlyingSource.releasePeriod(mediaPeriod);
        }

        @Override
        protected void onChildSourceInfoRefreshed(Void id, MediaSource mediaSource, Timeline timeline) {
            refreshSourceInfo(timeline);
        }

        @Override
        public boolean isSingleWindow() {
            return false;
        }

        @Override
        public MediaItem getMediaItem() {
            return underlyingSource.getMediaItem();
        }

        @Override
        @Nullable
        public Timeline getInitialTimeline() {
            return Timeline.EMPTY;
        }
    };
    int[] currentMediaItemIndices = new int[1];
    long[] currentPlaybackPositions = new long[1];
    long[] windowCounts = new long[1];
    int seekToMediaItemIndex = 1;
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).seek(/* mediaItemIndex= */
    1, /* positionMs= */
    5000).waitForTimelineChanged(/* expectedTimeline= */
    null, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
            currentPlaybackPositions[0] = player.getCurrentPosition();
            windowCounts[0] = player.getCurrentTimeline().getWindowCount();
        }
    }).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(delegatingMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
    assertArrayEquals(new long[] { 2 }, windowCounts);
    assertArrayEquals(new int[] { seekToMediaItemIndex }, currentMediaItemIndices);
    assertArrayEquals(new long[] { 5_000 }, currentPlaybackPositions);
}
Also used : TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Allocator(com.google.android.exoplayer2.upstream.Allocator) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) 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) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 3 with ExoPlayerTestRunner

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

the class ExoPlayerTest method modifyPlaylistUnprepared_remainsInIdle_needsPrepareForBuffering.

@Test
public void modifyPlaylistUnprepared_remainsInIdle_needsPrepareForBuffering() throws Exception {
    int[] playbackStates = new int[4];
    int[] timelineWindowCounts = new int[4];
    int[] maskingPlaybackState = { C.INDEX_UNSET };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForTimelineChanged(placeholderTimeline, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED).executeRunnable(new PlaybackStateCollector(/* index= */
    0, playbackStates, timelineWindowCounts)).clearMediaItems().executeRunnable(new PlaybackStateCollector(/* index= */
    1, playbackStates, timelineWindowCounts)).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            player.setMediaSource(new FakeMediaSource(), /* startPositionMs= */
            1000);
            maskingPlaybackState[0] = player.getPlaybackState();
        }
    }).executeRunnable(new PlaybackStateCollector(/* index= */
    2, playbackStates, timelineWindowCounts)).addMediaSources(new FakeMediaSource()).executeRunnable(new PlaybackStateCollector(/* index= */
    3, playbackStates, timelineWindowCounts)).seek(/* mediaItemIndex= */
    1, /* positionMs= */
    2000).prepare().waitForPlaybackState(Player.STATE_BUFFERING).waitForPlaybackState(Player.STATE_READY).waitForPlaybackState(Player.STATE_ENDED).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(new FakeMediaSource()).setActionSchedule(actionSchedule).build().start(/* doPrepare= */
    false).blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertArrayEquals(new int[] { Player.STATE_IDLE, Player.STATE_IDLE, Player.STATE_IDLE, Player.STATE_IDLE }, playbackStates);
    assertArrayEquals(new int[] { 1, 0, 1, 2 }, timelineWindowCounts);
    exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_BUFFERING, /* first buffering state after prepare */
    Player.STATE_READY, Player.STATE_ENDED);
    exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* initial setMediaSources */
    Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* clear */
    Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* set media items */
    Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* add media items */
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
    Timeline expectedSecondPlaceholderTimeline = new FakeTimeline(TimelineWindowDefinition.createPlaceholder(/* tag= */
    0), TimelineWindowDefinition.createPlaceholder(/* tag= */
    0));
    Timeline expectedSecondRealTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    10_000_000), new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    10_000_000));
    exoPlayerTestRunner.assertTimelinesSame(placeholderTimeline, Timeline.EMPTY, placeholderTimeline, expectedSecondPlaceholderTimeline, expectedSecondRealTimeline);
    assertArrayEquals(new int[] { Player.STATE_IDLE }, maskingPlaybackState);
}
Also used : NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) 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) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 4 with ExoPlayerTestRunner

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

the class ExoPlayerTest method stopWithNoReset_modifyingPlaylistRemainsInIdleState_needsPrepareForBuffering.

@Test
public void stopWithNoReset_modifyingPlaylistRemainsInIdleState_needsPrepareForBuffering() throws Exception {
    Timeline timeline = new FakeTimeline();
    FakeMediaSource secondMediaSource = new FakeMediaSource(timeline);
    int[] playbackStateHolder = new int[3];
    int[] windowCountHolder = new int[3];
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).stop(/* reset= */
    false).executeRunnable(new PlaybackStateCollector(/* index= */
    0, playbackStateHolder, windowCountHolder)).clearMediaItems().executeRunnable(new PlaybackStateCollector(/* index= */
    1, playbackStateHolder, windowCountHolder)).addMediaSources(secondMediaSource).executeRunnable(new PlaybackStateCollector(/* index= */
    2, playbackStateHolder, windowCountHolder)).prepare().waitForPlaybackState(Player.STATE_BUFFERING).waitForPlaybackState(Player.STATE_READY).waitForPlaybackState(Player.STATE_ENDED).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertArrayEquals(new int[] { Player.STATE_IDLE, Player.STATE_IDLE, Player.STATE_IDLE }, playbackStateHolder);
    assertArrayEquals(new int[] { 1, 0, 1 }, windowCountHolder);
    exoPlayerTestRunner.assertPlaybackStatesEqual(// first buffering
    Player.STATE_BUFFERING, Player.STATE_READY, // stop
    Player.STATE_IDLE, Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED);
    exoPlayerTestRunner.assertTimelinesSame(placeholderTimeline, timeline, Timeline.EMPTY, placeholderTimeline, timeline);
    exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* media item set (masked timeline) */
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, /* source prepared */
    Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* clear media items */
    Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* media item add (masked timeline) */
    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) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) 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 5 with ExoPlayerTestRunner

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

the class ExoPlayerTest method setMediaSources_whenIdle_noSeekEmpty_correctMaskingPlaybackState.

@Test
public void setMediaSources_whenIdle_noSeekEmpty_correctMaskingPlaybackState() throws Exception {
    final int[] maskingPlaybackStates = new int[1];
    Arrays.fill(maskingPlaybackStates, C.INDEX_UNSET);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Set an empty media item with no seek.
            player.setMediaSource(new ConcatenatingMediaSource());
            maskingPlaybackStates[0] = player.getPlaybackState();
        }
    }).setMediaSources(new FakeMediaSource()).prepare().waitForPlaybackState(Player.STATE_READY).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).skipSettingMediaSources().setActionSchedule(actionSchedule).build().start(/* doPrepare= */
    false).blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    // Expect reset of masking to first media item.
    exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED);
    assertArrayEquals(new int[] { Player.STATE_IDLE }, maskingPlaybackStates);
    exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) 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)

Aggregations

ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)51 Test (org.junit.Test)51 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)49 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)42 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)41 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)41 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)33 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)33 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)26 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)23 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)16 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)16 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)16 MediaSource (com.google.android.exoplayer2.source.MediaSource)16 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)16 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)16 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)15 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)7 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)7 IOException (java.io.IOException)7