Search in sources :

Example 11 with FakeMediaSource

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

the class ExoPlayerTest method mediaSourceMaybeThrowSourceInfoRefreshError_isNotThrownUntilPlaybackReachedFailingItem.

@Test
public void mediaSourceMaybeThrowSourceInfoRefreshError_isNotThrownUntilPlaybackReachedFailingItem() throws Exception {
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addMediaSource(new FakeMediaSource());
    player.addMediaSource(new FakeMediaSource(/* timeline= */
    null) {

        @Override
        public void maybeThrowSourceInfoRefreshError() throws IOException {
            throw new IOException();
        }
    });
    player.prepare();
    player.play();
    ExoPlaybackException error = TestPlayerRunHelper.runUntilError(player);
    Object period1Uid = player.getCurrentTimeline().getPeriod(/* periodIndex= */
    1, new Timeline.Period(), /* setIds= */
    true).uid;
    assertThat(error.mediaPeriodId.periodUid).isEqualTo(period1Uid);
    assertThat(player.getCurrentMediaItemIndex()).isEqualTo(1);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) IOException(java.io.IOException) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 12 with FakeMediaSource

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

the class ExoPlayerTest method setMediaSources_whenEmpty_invalidInitialSeek_correctMasking.

@Test
public void setMediaSources_whenEmpty_invalidInitialSeek_correctMasking() throws Exception {
    final int[] currentMediaItemIndices = { C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET };
    final long[] currentPositions = { 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).waitForPositionDiscontinuity().waitForPendingPlayerCommands().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
            currentPositions[0] = player.getCurrentPosition();
            bufferedPositions[0] = player.getBufferedPosition();
            // Increase current media item index.
            player.addMediaSource(/* index= */
            0, new FakeMediaSource());
            currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
            currentPositions[1] = player.getCurrentPosition();
            bufferedPositions[1] = player.getBufferedPosition();
        }
    }).prepare().waitForTimelineChanged().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndices[2] = player.getCurrentMediaItemIndex();
            currentPositions[2] = player.getCurrentPosition();
            bufferedPositions[2] = player.getBufferedPosition();
        }
    }).waitForPlaybackState(Player.STATE_ENDED).build();
    new ExoPlayerTestRunner.Builder(context).initialSeek(/* mediaItemIndex= */
    1, 2000).setMediaSources(new FakeMediaSource()).setActionSchedule(actionSchedule).build().start(/* doPrepare= */
    false).blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertArrayEquals(new int[] { 0, 1, 1 }, currentMediaItemIndices);
    assertArrayEquals(new long[] { 0, 0, 0 }, currentPositions);
    assertArrayEquals(new long[] { 0, 0, 0 }, bufferedPositions);
}
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) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 13 with FakeMediaSource

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

the class ExoPlayerTest method invalidSeekFallsBackToSubsequentPeriodOfTheRemovedPeriod.

@Test
public void invalidSeekFallsBackToSubsequentPeriodOfTheRemovedPeriod() throws Exception {
    Timeline timeline = new FakeTimeline();
    CountDownLatch sourceReleasedCountDownLatch = new CountDownLatch(/* count= */
    1);
    MediaSource mediaSourceToRemove = new FakeMediaSource(timeline) {

        @Override
        protected void releaseSourceInternal() {
            super.releaseSourceInternal();
            sourceReleasedCountDownLatch.countDown();
        }
    };
    ConcatenatingMediaSource mediaSource = new ConcatenatingMediaSource(mediaSourceToRemove, new FakeMediaSource(timeline));
    final int[] windowCount = { C.INDEX_UNSET };
    final long[] position = { C.TIME_UNSET };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            mediaSource.removeMediaSource(/* index= */
            0);
            try {
                // Wait until the source to be removed is released on the playback thread. So
                // the timeline in EPII has one window only, but the update here in EPI is
                // stuck until we finished our executable here. So when seeking below, we will
                // seek in the timeline which still has two windows in EPI, but when the seek
                // arrives in EPII the actual timeline has one window only. Hence it tries to
                // find the subsequent period of the removed period and finds it.
                player.getClock().onThreadBlocked();
                sourceReleasedCountDownLatch.await();
            } catch (InterruptedException e) {
                throw new IllegalStateException(e);
            }
            player.seekTo(/* mediaItemIndex= */
            0, /* positionMs= */
            1000L);
        }
    }).waitForPendingPlayerCommands().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            windowCount[0] = player.getCurrentTimeline().getWindowCount();
            position[0] = player.getCurrentPosition();
        }
    }).play().build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    // Expect the first window to be the current.
    assertThat(windowCount[0]).isEqualTo(1);
    // Expect the position to be in the default position.
    assertThat(position[0]).isEqualTo(0L);
}
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) CountDownLatch(java.util.concurrent.CountDownLatch) 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) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) Test(org.junit.Test)

Example 14 with FakeMediaSource

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

the class ExoPlayerTest method isCommandAvailable_duringUnseekableLiveItem_isFalseForSeekToPrevious.

@Test
public void isCommandAvailable_duringUnseekableLiveItem_isFalseForSeekToPrevious() throws Exception {
    Timeline timelineWithUnseekableLiveWindow = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    false, /* isDynamic= */
    true, /* isLive= */
    true, /* isPlaceholder= */
    false, /* durationUs= */
    C.TIME_UNSET, /* defaultPositionUs= */
    10_000_000, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, AdPlaybackState.NONE));
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addMediaSource(new FakeMediaSource(timelineWithUnseekableLiveWindow));
    player.prepare();
    runUntilPlaybackState(player, Player.STATE_READY);
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS)).isFalse();
}
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) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 15 with FakeMediaSource

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

the class ExoPlayerTest method moveMediaItem.

@Test
public void moveMediaItem() throws Exception {
    TimelineWindowDefinition firstWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    1, /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    Util.msToUs(10000));
    TimelineWindowDefinition secondWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    2, /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    Util.msToUs(10000));
    Timeline timeline1 = new FakeTimeline(firstWindowDefinition);
    Timeline timeline2 = new FakeTimeline(secondWindowDefinition);
    MediaSource mediaSource1 = new FakeMediaSource(timeline1);
    MediaSource mediaSource2 = new FakeMediaSource(timeline2);
    Timeline expectedPlaceholderTimeline = new FakeTimeline(TimelineWindowDefinition.createPlaceholder(/* tag= */
    1), TimelineWindowDefinition.createPlaceholder(/* tag= */
    2));
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForTimelineChanged(/* expectedTimeline= */
    null, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).moveMediaItem(/* currentIndex= */
    0, /* newIndex= */
    1).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource1, mediaSource2).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    Timeline expectedRealTimeline = new FakeTimeline(firstWindowDefinition, secondWindowDefinition);
    Timeline expectedRealTimelineAfterMove = new FakeTimeline(secondWindowDefinition, firstWindowDefinition);
    exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
    exoPlayerTestRunner.assertTimelinesSame(expectedPlaceholderTimeline, expectedRealTimeline, expectedRealTimelineAfterMove);
}
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) 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)

Aggregations

FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)262 Test (org.junit.Test)252 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)177 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)169 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)113 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)111 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)109 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)94 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)93 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)89 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)84 MediaSource (com.google.android.exoplayer2.source.MediaSource)76 Listener (com.google.android.exoplayer2.Player.Listener)64 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)53 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)52 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)52 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)52 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)52 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)45 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)44