use of androidx.media3.test.utils.FakeTimeline in project media by androidx.
the class ExoPlayerTest method timelineUpdateDropsPrebufferedPeriods.
@Test
public void timelineUpdateDropsPrebufferedPeriods() throws Exception {
Timeline timeline1 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
2));
final Timeline timeline2 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
3));
final FakeMediaSource mediaSource = new FakeMediaSource(timeline1, ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).playUntilPosition(/* mediaItemIndex= */
0, /* positionMs= */
Util.usToMs(TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US)).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.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
testRunner.assertPlayedPeriodIndices(0, 1);
// Assert that the second period was re-created from the new timeline.
assertThat(mediaSource.getCreatedMediaPeriods()).hasSize(3);
assertThat(mediaSource.getCreatedMediaPeriods().get(0).periodUid).isEqualTo(timeline1.getUidOfPeriod(/* periodIndex= */
0));
assertThat(mediaSource.getCreatedMediaPeriods().get(1).periodUid).isEqualTo(timeline1.getUidOfPeriod(/* periodIndex= */
1));
assertThat(mediaSource.getCreatedMediaPeriods().get(2).periodUid).isEqualTo(timeline2.getUidOfPeriod(/* periodIndex= */
1));
assertThat(mediaSource.getCreatedMediaPeriods().get(1).windowSequenceNumber).isGreaterThan(mediaSource.getCreatedMediaPeriods().get(0).windowSequenceNumber);
assertThat(mediaSource.getCreatedMediaPeriods().get(2).windowSequenceNumber).isGreaterThan(mediaSource.getCreatedMediaPeriods().get(1).windowSequenceNumber);
}
use of androidx.media3.test.utils.FakeTimeline in project media by androidx.
the class ExoPlayerTest method playShortDurationPeriods.
/**
* Tests playback of periods with very short duration.
*/
@Test
public void playShortDurationPeriods() throws Exception {
// TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US / 100 = 1000 us per period.
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
100, /* id= */
0));
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 = inOrder(mockPlayerListener);
inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(placeholderTimeline)), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(timeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
inOrder.verify(mockPlayerListener, times(99)).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
assertThat(renderer.getFormatsRead()).hasSize(100);
assertThat(renderer.sampleBufferReadCount).isEqualTo(100);
assertThat(renderer.isEnded).isTrue();
}
use of androidx.media3.test.utils.FakeTimeline in project media by androidx.
the class ExoPlayerTest method stop_withoutReset_releasesMediaSource.
@Test
public void stop_withoutReset_releasesMediaSource() throws Exception {
Timeline timeline = new FakeTimeline();
final FakeMediaSource mediaSource = new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).stop(/* reset= */
false).build();
new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
mediaSource.assertReleased();
}
use of androidx.media3.test.utils.FakeTimeline in project media by androidx.
the class ExoPlayerTest method sendMessagesMoveCurrentMediaItemIndex.
@Test
public void sendMessagesMoveCurrentMediaItemIndex() throws Exception {
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0));
final Timeline secondTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0));
final FakeMediaSource mediaSource = new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT);
PositionGrabbingMessageTarget target = new PositionGrabbingMessageTarget();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForTimelineChanged(timeline, /* expectedReason */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).sendMessage(target, /* positionMs= */
50).executeRunnable(() -> mediaSource.setNewSourceInfo(secondTimeline)).waitForTimelineChanged(secondTimeline, /* expectedReason */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).play().build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(target.positionMs).isAtLeast(50L);
assertThat(target.mediaItemIndex).isEqualTo(1);
}
use of androidx.media3.test.utils.FakeTimeline in project media by androidx.
the class ExoPlayerTest method seekToNext_liveWindowWithoutNextWindow_seeksToLiveEdge.
@Test
public void seekToNext_liveWindowWithoutNextWindow_seeksToLiveEdge() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
1_000_000, /* defaultPositionUs= */
500_000, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, AdPlaybackState.NONE));
MediaSource mediaSource = new FakeMediaSource(timeline);
player.setMediaSource(mediaSource);
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
player.seekTo(/* positionMs = */
0);
player.seekToNext();
assertThat(player.getCurrentMediaItemIndex()).isEqualTo(0);
assertThat(player.getCurrentPosition()).isEqualTo(500);
player.release();
}
Aggregations