Search in sources :

Example 11 with PlaceholderTimeline

use of com.google.android.exoplayer2.source.MaskingMediaSource.PlaceholderTimeline in project ExoPlayer by google.

the class ClippingMediaSourceTest method clippingStartAndEndInitial.

@Test
public void clippingStartAndEndInitial() throws IOException {
    // Timeline that's dynamic and not seekable. A child source might report such a timeline prior
    // to it having loaded sufficient data to establish its duration and seekability. Such timelines
    // should not result in clipping failure.
    Timeline timeline = new PlaceholderTimeline(MediaItem.fromUri(Uri.EMPTY));
    Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US, TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
    assertThat(clippedTimeline.getWindow(0, window).getDurationUs()).isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
    assertThat(clippedTimeline.getPeriod(0, period).getDurationUs()).isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
}
Also used : PlaceholderTimeline(com.google.android.exoplayer2.source.MaskingMediaSource.PlaceholderTimeline) Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) PlaceholderTimeline(com.google.android.exoplayer2.source.MaskingMediaSource.PlaceholderTimeline) Test(org.junit.Test)

Example 12 with PlaceholderTimeline

use of com.google.android.exoplayer2.source.MaskingMediaSource.PlaceholderTimeline in project ExoPlayer by google.

the class ExoPlayerTest method modifyPlaylistPrepared_remainsInEnded_needsSeekForBuffering.

@Test
public void modifyPlaylistPrepared_remainsInEnded_needsSeekForBuffering() throws Exception {
    Timeline timeline = new FakeTimeline();
    FakeMediaSource secondMediaSource = new FakeMediaSource(timeline);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForTimelineChanged(timeline, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).waitForPlaybackState(Player.STATE_BUFFERING).waitForPlaybackState(Player.STATE_READY).clearMediaItems().waitForPlaybackState(Player.STATE_ENDED).addMediaSources(// add must not transition to buffering
    secondMediaSource).waitForTimelineChanged().clearMediaItems().addMediaSources(// add again to be able to test the seek
    secondMediaSource).waitForTimelineChanged().seek(/* positionMs= */
    2_000).waitForPlaybackState(Player.STATE_BUFFERING).waitForPlaybackState(Player.STATE_READY).waitForPlaybackState(Player.STATE_ENDED).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setExpectedPlayerEndedCount(/* expectedPlayerEndedCount= */
    2).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    exoPlayerTestRunner.assertPlaybackStatesEqual(// first buffering
    Player.STATE_BUFFERING, Player.STATE_READY, // clear playlist
    Player.STATE_ENDED, // second buffering after seek
    Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED);
    exoPlayerTestRunner.assertTimelinesSame(placeholderTimeline, timeline, Timeline.EMPTY, 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, /* playlist cleared */
    Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* media items added */
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, /* source prepared */
    Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* playlist cleared */
    Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* media items added */
    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) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 13 with PlaceholderTimeline

use of com.google.android.exoplayer2.source.MaskingMediaSource.PlaceholderTimeline in project ExoPlayer by google.

the class ExoPlayerTest method stopDuringPreparationOverwritesPreparation.

@Test
public void stopDuringPreparationOverwritesPreparation() throws Exception {
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_BUFFERING).stop(true).waitForPendingPlayerCommands().build();
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(new FakeTimeline()).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    testRunner.assertTimelinesSame(placeholderTimeline, Timeline.EMPTY);
    testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
}
Also used : 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 14 with PlaceholderTimeline

use of com.google.android.exoplayer2.source.MaskingMediaSource.PlaceholderTimeline in project ExoPlayer by google.

the class ExoPlayerTest method resettingMediaSourcesGivesFreshSourceInfo.

@Test
public void resettingMediaSourcesGivesFreshSourceInfo() throws Exception {
    FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    Timeline firstTimeline = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    1_000_000_000));
    MediaSource firstSource = new FakeMediaSource(firstTimeline, ExoPlayerTestRunner.VIDEO_FORMAT);
    AtomicBoolean secondSourcePrepared = new AtomicBoolean();
    MediaSource secondSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT) {

        @Override
        public synchronized void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
            super.prepareSourceInternal(mediaTransferListener);
            secondSourcePrepared.set(true);
        }
    };
    Timeline thirdTimeline = new FakeTimeline();
    MediaSource thirdSource = new FakeMediaSource(thirdTimeline, ExoPlayerTestRunner.VIDEO_FORMAT);
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
    Player.Listener mockPlayerListener = mock(Player.Listener.class);
    player.addListener(mockPlayerListener);
    player.setMediaSource(firstSource);
    player.prepare();
    player.play();
    runUntilTimelineChanged(player);
    player.setMediaSource(secondSource);
    runMainLooperUntil(secondSourcePrepared::get);
    player.setMediaSource(thirdSource);
    runUntilPlaybackState(player, Player.STATE_ENDED);
    // The first source's preparation completed with a real timeline. When the second source was
    // prepared, it immediately exposed a placeholder timeline, but the source info refresh from the
    // second source was suppressed as we replace it with the third source before the update
    // arrives.
    InOrder inOrder = inOrder(mockPlayerListener);
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(placeholderTimeline)), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(firstTimeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(placeholderTimeline)), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockPlayerListener).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_REMOVE));
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(placeholderTimeline)), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockPlayerListener).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_REMOVE));
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(thirdTimeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
    inOrder.verify(mockPlayerListener).onTracksChanged(eq(new TrackGroupArray(new TrackGroup(ExoPlayerTestRunner.VIDEO_FORMAT))), any());
    assertThat(renderer.isEnded).isTrue();
}
Also used : TransferListener(com.google.android.exoplayer2.upstream.TransferListener) InOrder(org.mockito.InOrder) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Listener(com.google.android.exoplayer2.Player.Listener) 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) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 15 with PlaceholderTimeline

use of com.google.android.exoplayer2.source.MaskingMediaSource.PlaceholderTimeline in project ExoPlayer by google.

the class ExoPlayerTest method settingNewStartPositionPossibleAfterStopWithReset.

@Test
public void settingNewStartPositionPossibleAfterStopWithReset() throws Exception {
    Timeline timeline = new FakeTimeline();
    Timeline secondTimeline = new FakeTimeline(/* windowCount= */
    2);
    MediaSource secondSource = new FakeMediaSource(secondTimeline, ExoPlayerTestRunner.VIDEO_FORMAT);
    AtomicInteger mediaItemIndexAfterStop = new AtomicInteger();
    AtomicLong positionAfterStop = new AtomicLong();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).stop(/* reset= */
    true).waitForPlaybackState(Player.STATE_IDLE).seek(/* mediaItemIndex= */
    1, /* positionMs= */
    1000).setMediaSources(secondSource).prepare().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            mediaItemIndexAfterStop.set(player.getCurrentMediaItemIndex());
            positionAfterStop.set(player.getCurrentPosition());
        }
    }).waitForPlaybackState(Player.STATE_READY).build();
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).setExpectedPlayerEndedCount(2).build().start().blockUntilEnded(TIMEOUT_MS);
    testRunner.assertPlaybackStatesEqual(Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_IDLE, Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED);
    testRunner.assertTimelinesSame(placeholderTimeline, timeline, Timeline.EMPTY, new FakeMediaSource.InitialTimeline(secondTimeline), secondTimeline);
    testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, // stop(true)
    Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
    assertThat(mediaItemIndexAfterStop.get()).isEqualTo(1);
    assertThat(positionAfterStop.get()).isAtLeast(1000L);
    testRunner.assertPlayedPeriodIndices(0, 1);
}
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) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Aggregations

FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)17 Test (org.junit.Test)17 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)15 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)15 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)14 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)12 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)12 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)11 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)5 Listener (com.google.android.exoplayer2.Player.Listener)4 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)3 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)3 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)3 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)3 MediaSource (com.google.android.exoplayer2.source.MediaSource)3 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)3 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)3 FakeRenderer (com.google.android.exoplayer2.testutil.FakeRenderer)3 InOrder (org.mockito.InOrder)3 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2