use of androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition in project media by androidx.
the class TimelineTest method singlePeriodTimeline.
@Test
public void singlePeriodTimeline() {
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(1, 111));
TimelineAsserts.assertWindowTags(timeline, 111);
TimelineAsserts.assertPeriodCounts(timeline, 1);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, C.INDEX_UNSET);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 0);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, C.INDEX_UNSET);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 0);
}
use of androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition in project media by androidx.
the class ExoPlayerTest method newServerSideInsertedAdAtPlaybackPosition_keepsRenderersEnabled.
@Test
public void newServerSideInsertedAdAtPlaybackPosition_keepsRenderersEnabled() throws Exception {
// Injecting renderer to count number of renderer resets.
AtomicReference<FakeVideoRenderer> videoRenderer = new AtomicReference<>();
ExoPlayer player = new TestExoPlayerBuilder(context).setRenderersFactory((handler, videoListener, audioListener, textOutput, metadataOutput) -> {
videoRenderer.set(new FakeVideoRenderer(handler, videoListener));
return new Renderer[] { videoRenderer.get() };
}).build();
// Live stream timeline with unassigned next ad group.
AdPlaybackState initialAdPlaybackState = new AdPlaybackState(/* adsId= */
new Object(), /* adGroupTimesUs...= */
C.TIME_END_OF_SOURCE).withIsServerSideInserted(/* adGroupIndex= */
0, /* isServerSideInserted= */
true).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1).withAdDurationsUs(new long[][] { new long[] { 10 * C.MICROS_PER_SECOND } });
// Updated timeline with ad group at 18 seconds.
long firstSampleTimeUs = TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
Timeline initialTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* durationUs= */
C.TIME_UNSET, initialAdPlaybackState));
AdPlaybackState updatedAdPlaybackState = initialAdPlaybackState.withAdGroupTimeUs(/* adGroupIndex= */
0, /* adGroupTimeUs= */
firstSampleTimeUs + 18 * C.MICROS_PER_SECOND);
Timeline updatedTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* durationUs= */
C.TIME_UNSET, updatedAdPlaybackState));
// Add samples to allow player to load and start playing (but no EOS as this is a live stream).
FakeMediaSource mediaSource = new FakeMediaSource(initialTimeline, DrmSessionManager.DRM_UNSUPPORTED, (format, mediaPeriodId) -> ImmutableList.of(oneByteSample(firstSampleTimeUs, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(firstSampleTimeUs + 40 * C.MICROS_PER_SECOND)), ExoPlayerTestRunner.VIDEO_FORMAT);
// Set updated ad group once we reach 20 seconds, and then continue playing until 40 seconds.
player.createMessage((message, payload) -> mediaSource.setNewSourceInfo(updatedTimeline)).setPosition(20_000).send();
player.setMediaSource(mediaSource);
player.prepare();
playUntilPosition(player, /* mediaItemIndex= */
0, /* positionMs= */
40_000);
player.release();
// Assert that the renderer hasn't been reset despite the inserted ad group.
assertThat(videoRenderer.get().positionResetCount).isEqualTo(1);
}
use of androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition in project media by androidx.
the class ExoPlayerTest method resetPlaylistWithPreviousPosition.
@Test
public void resetPlaylistWithPreviousPosition() throws Exception {
Object firstWindowId = new Object();
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
firstWindowId));
Timeline firstExpectedMaskingTimeline = new MaskingMediaSource.PlaceholderTimeline(FakeTimeline.FAKE_MEDIA_ITEM.buildUpon().setTag(firstWindowId).build());
Object secondWindowId = new Object();
Timeline secondTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
secondWindowId));
Timeline secondExpectedMaskingTimeline = new MaskingMediaSource.PlaceholderTimeline(FakeTimeline.FAKE_MEDIA_ITEM.buildUpon().setTag(secondWindowId).build());
MediaSource secondSource = new FakeMediaSource(secondTimeline);
AtomicLong positionAfterReprepare = new AtomicLong();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).playUntilPosition(/* mediaItemIndex= */
0, /* positionMs= */
2000).setMediaSources(/* mediaItemIndex= */
0, /* positionMs= */
2000, secondSource).waitForTimelineChanged(secondTimeline, /* expectedReason */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
positionAfterReprepare.set(player.getCurrentPosition());
}
}).play().build();
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
testRunner.assertTimelinesSame(firstExpectedMaskingTimeline, timeline, secondExpectedMaskingTimeline, secondTimeline);
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);
assertThat(positionAfterReprepare.get()).isAtLeast(2000L);
}
use of androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition in project media by androidx.
the class ExoPlayerTest method timelineUpdateInMultiWindowMediaSource_removingPeriod_withUnpreparedMaskingMediaPeriod_doesNotThrow.
@Test
public void timelineUpdateInMultiWindowMediaSource_removingPeriod_withUnpreparedMaskingMediaPeriod_doesNotThrow() throws Exception {
TimelineWindowDefinition window1 = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1);
TimelineWindowDefinition window2 = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
2);
FakeMediaSource mediaSource = new FakeMediaSource(/* timeline= */
null);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_BUFFERING).waitForPendingPlayerCommands().executeRunnable(() -> mediaSource.setNewSourceInfo(new FakeTimeline(window1, window2))).waitForTimelineChanged().executeRunnable(() -> mediaSource.setNewSourceInfo(new FakeTimeline(window2))).waitForTimelineChanged().stop().build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
// Assertion is to not throw while running the action schedule above.
}
use of androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition 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);
}
Aggregations