use of androidx.media3.test.utils.FakeTimeline in project media by androidx.
the class TimelineTest method roundTripViaBundle_ofTimeline_preservesWindowIndices.
@Test
public void roundTripViaBundle_ofTimeline_preservesWindowIndices() {
int windowCount = 10;
FakeTimeline timeline = new FakeTimeline(windowCount);
Timeline restoredTimeline = Timeline.CREATOR.fromBundle(timeline.toBundle());
assertThat(restoredTimeline.getLastWindowIndex(/* shuffleModeEnabled= */
false)).isEqualTo(timeline.getLastWindowIndex(/* shuffleModeEnabled= */
false));
assertThat(restoredTimeline.getLastWindowIndex(/* shuffleModeEnabled= */
true)).isEqualTo(timeline.getLastWindowIndex(/* shuffleModeEnabled= */
true));
assertThat(restoredTimeline.getFirstWindowIndex(/* shuffleModeEnabled= */
false)).isEqualTo(timeline.getFirstWindowIndex(/* shuffleModeEnabled= */
false));
assertThat(restoredTimeline.getFirstWindowIndex(/* shuffleModeEnabled= */
true)).isEqualTo(timeline.getFirstWindowIndex(/* shuffleModeEnabled= */
true));
TimelineAsserts.assertEqualNextWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
false);
TimelineAsserts.assertEqualNextWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
true);
TimelineAsserts.assertEqualNextWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
false);
TimelineAsserts.assertEqualNextWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
true);
TimelineAsserts.assertEqualNextWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
false);
TimelineAsserts.assertEqualNextWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
true);
TimelineAsserts.assertEqualPreviousWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
false);
TimelineAsserts.assertEqualPreviousWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
true);
TimelineAsserts.assertEqualPreviousWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
false);
TimelineAsserts.assertEqualPreviousWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
true);
TimelineAsserts.assertEqualPreviousWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
false);
TimelineAsserts.assertEqualPreviousWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
true);
}
use of androidx.media3.test.utils.FakeTimeline 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 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 in project media by androidx.
the class ExoPlayerTest method setPlaybackSpeedBeforePreparationCompletesSucceeds.
@Test
public void setPlaybackSpeedBeforePreparationCompletesSucceeds() throws Exception {
// Test that no exception is thrown when playback parameters are updated between creating a
// period and preparation of the period completing.
final CountDownLatch createPeriodCalledCountDownLatch = new CountDownLatch(1);
final FakeMediaPeriod[] fakeMediaPeriodHolder = new FakeMediaPeriod[1];
MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT) {
@Override
protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
// Defer completing preparation of the period until playback parameters have been set.
fakeMediaPeriodHolder[0] = new FakeMediaPeriod(trackGroupArray, allocator, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
true);
createPeriodCalledCountDownLatch.countDown();
return fakeMediaPeriodHolder[0];
}
};
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
try {
player.getClock().onThreadBlocked();
createPeriodCalledCountDownLatch.await();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
}).setPlaybackParameters(new PlaybackParameters(/* speed= */
2f)).executeRunnable(() -> fakeMediaPeriodHolder[0].setPreparationComplete()).build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
}
use of androidx.media3.test.utils.FakeTimeline in project media by androidx.
the class ExoPlayerTest method mediaPeriodMaybeThrowPrepareError_isNotThrownUntilPlaybackReachedFailingItem.
@Test
public void mediaPeriodMaybeThrowPrepareError_isNotThrownUntilPlaybackReachedFailingItem() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Timeline timeline = new FakeTimeline();
player.addMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
player.addMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT) {
@Override
protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
return new FakeMediaPeriod(trackGroupArray, allocator, /* singleSampleTimeUs= */
0, mediaSourceEventDispatcher, DrmSessionManager.DRM_UNSUPPORTED, drmEventDispatcher, /* deferOnPrepared= */
true) {
@Override
public void maybeThrowPrepareError() 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);
}
Aggregations