Search in sources :

Example 96 with FakeTimeline

use of androidx.media3.test.utils.FakeTimeline in project media by androidx.

the class ExoPlayerTest method release_correctMasking.

@Test
public void release_correctMasking() throws Exception {
    int[] currentMediaItemIndex = { C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET };
    long[] currentPosition = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
    long[] bufferedPosition = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
    long[] totalBufferedDuration = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
    final FakeMediaSource mediaSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().seek(/* mediaItemIndex= */
    1, /* positionMs= */
    1000).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndex[0] = player.getCurrentMediaItemIndex();
            currentPosition[0] = player.getCurrentPosition();
            bufferedPosition[0] = player.getBufferedPosition();
            totalBufferedDuration[0] = player.getTotalBufferedDuration();
            player.release();
            currentMediaItemIndex[1] = player.getCurrentMediaItemIndex();
            currentPosition[1] = player.getCurrentPosition();
            bufferedPosition[1] = player.getBufferedPosition();
            totalBufferedDuration[1] = player.getTotalBufferedDuration();
        }
    }).waitForPlaybackState(Player.STATE_IDLE).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndex[2] = player.getCurrentMediaItemIndex();
            currentPosition[2] = player.getCurrentPosition();
            bufferedPosition[2] = player.getBufferedPosition();
            totalBufferedDuration[2] = player.getTotalBufferedDuration();
        }
    }).build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource, mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS);
    assertThat(currentMediaItemIndex[0]).isEqualTo(1);
    assertThat(currentPosition[0]).isGreaterThan(0);
    assertThat(bufferedPosition[0]).isEqualTo(10000);
    assertThat(totalBufferedDuration[0]).isEqualTo(10000 - currentPosition[0]);
    assertThat(currentMediaItemIndex[1]).isEqualTo(1);
    assertThat(currentPosition[1]).isEqualTo(currentPosition[0]);
    assertThat(bufferedPosition[1]).isEqualTo(1000);
    assertThat(totalBufferedDuration[1]).isEqualTo(0);
    assertThat(currentMediaItemIndex[2]).isEqualTo(1);
    assertThat(currentPosition[2]).isEqualTo(currentPosition[0]);
    assertThat(bufferedPosition[2]).isEqualTo(1000);
    assertThat(totalBufferedDuration[2]).isEqualTo(0);
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) FakeTimeline(androidx.media3.test.utils.FakeTimeline) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Test(org.junit.Test)

Example 97 with FakeTimeline

use of androidx.media3.test.utils.FakeTimeline in project media by androidx.

the class ExoPlayerTest method clearMediaItems.

@Test
public void clearMediaItems() throws Exception {
    Timeline timeline = new FakeTimeline();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForTimelineChanged(timeline, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).waitForPlaybackState(Player.STATE_READY).clearMediaItems().waitForPlaybackState(Player.STATE_ENDED).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED);
    exoPlayerTestRunner.assertTimelinesSame(placeholderTimeline, timeline, Timeline.EMPTY);
    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);
}
Also used : Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) ActionSchedule(androidx.media3.test.utils.ActionSchedule) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Test(org.junit.Test)

Example 98 with FakeTimeline

use of androidx.media3.test.utils.FakeTimeline in project media by androidx.

the class ExoPlayerTest method playbackErrorTwiceStillKeepsTimeline.

@Test
public void playbackErrorTwiceStillKeepsTimeline() throws Exception {
    final Timeline timeline = new FakeTimeline();
    final FakeMediaSource mediaSource2 = new FakeMediaSource(timeline);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).throwPlaybackException(ExoPlaybackException.createForSource(new IOException(), PlaybackException.ERROR_CODE_IO_UNSPECIFIED)).waitForPlaybackState(Player.STATE_IDLE).setMediaSources(/* resetPosition= */
    false, mediaSource2).prepare().waitForPlaybackState(Player.STATE_BUFFERING).throwPlaybackException(ExoPlaybackException.createForSource(new IOException(), PlaybackException.ERROR_CODE_IO_UNSPECIFIED)).waitForTimelineChanged(timeline, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).waitForPlaybackState(Player.STATE_IDLE).build();
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build();
    try {
        testRunner.start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
        fail();
    } catch (ExoPlaybackException e) {
    // Expected exception.
    }
    testRunner.assertTimelinesSame(placeholderTimeline, timeline, placeholderTimeline, timeline);
    testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
Also used : Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) FakeTimeline(androidx.media3.test.utils.FakeTimeline) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) IOException(java.io.IOException) Test(org.junit.Test)

Example 99 with FakeTimeline

use of androidx.media3.test.utils.FakeTimeline in project media by androidx.

the class ExoPlayerTest method playMultiPeriodTimeline.

/**
 * Tests playback of a source that exposes three periods.
 */
@Test
public void playMultiPeriodTimeline() throws Exception {
    Timeline timeline = new FakeTimeline(/* windowCount= */
    3);
    FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
    Player.Listener mockPlayerListener = mock(Player.Listener.class);
    player.addListener(mockPlayerListener);
    player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
    player.prepare();
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    InOrder inOrder = Mockito.inOrder(mockPlayerListener);
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(new FakeMediaSource.InitialTimeline(timeline))), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(timeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
    inOrder.verify(mockPlayerListener, times(2)).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    assertThat(renderer.getFormatsRead()).containsExactly(ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.VIDEO_FORMAT);
    assertThat(renderer.sampleBufferReadCount).isEqualTo(3);
    assertThat(renderer.isEnded).isTrue();
}
Also used : FakeRenderer(androidx.media3.test.utils.FakeRenderer) Listener(androidx.media3.common.Player.Listener) Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) Player(androidx.media3.common.Player) InOrder(org.mockito.InOrder) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 100 with FakeTimeline

use of androidx.media3.test.utils.FakeTimeline in project media by androidx.

the class ExoPlayerTest method targetLiveOffsetInMedia_withUserSeek_adjustsLiveOffsetToSeek.

@Test
public void targetLiveOffsetInMedia_withUserSeek_adjustsLiveOffsetToSeek() throws Exception {
    long windowStartUnixTimeMs = 987_654_321_000L;
    long nowUnixTimeMs = windowStartUnixTimeMs + 20_000;
    ExoPlayer player = new TestExoPlayerBuilder(context).setClock(new FakeClock(/* initialTimeMs= */
    nowUnixTimeMs, /* isAutoAdvancing= */
    true)).build();
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    true, /* isLive= */
    true, /* isPlaceholder= */
    false, /* durationUs= */
    1000 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
    8 * C.MICROS_PER_SECOND, /* windowOffsetInFirstPeriodUs= */
    Util.msToUs(windowStartUnixTimeMs), ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(9_000).build()).build()));
    player.pause();
    player.setMediaSource(new FakeMediaSource(timeline));
    player.prepare();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
    long liveOffsetAtStart = player.getCurrentLiveOffset();
    // Verify test setup (now = 20 seconds in live window, default start position = 8 seconds).
    assertThat(liveOffsetAtStart).isIn(Range.closed(11_900L, 12_100L));
    // Seek to a live offset of 2 seconds.
    player.seekTo(18_000);
    // Play until close to the end of the available live window.
    TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
    0, /* positionMs= */
    999_000);
    long liveOffsetAtEnd = player.getCurrentLiveOffset();
    player.release();
    // Assert the live offset adjustment was permanent.
    assertThat(liveOffsetAtEnd).isIn(Range.closed(1_900L, 2_100L));
}
Also used : Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeClock(androidx.media3.test.utils.FakeClock) FakeTimeline(androidx.media3.test.utils.FakeTimeline) MediaItem(androidx.media3.common.MediaItem) TestPlayerRunHelper.playUntilStartOfMediaItem(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

FakeTimeline (androidx.media3.test.utils.FakeTimeline)242 Test (org.junit.Test)240 Timeline (androidx.media3.common.Timeline)171 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)159 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)136 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)118 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)117 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)117 ActionSchedule (androidx.media3.test.utils.ActionSchedule)98 ExoPlayerTestRunner (androidx.media3.test.utils.ExoPlayerTestRunner)87 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)69 AdPlaybackState (androidx.media3.common.AdPlaybackState)63 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)62 PlayerRunnable (androidx.media3.test.utils.ActionSchedule.PlayerRunnable)60 MediaSource (androidx.media3.exoplayer.source.MediaSource)57 Player (androidx.media3.common.Player)51 ServerSideAdInsertionMediaSource (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource)50 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)49 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)49 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)49