use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class ExoPlayerTest method testPlaySinglePeriodTimeline.
/**
* Tests playback of a source that exposes a single period.
*/
public void testPlaySinglePeriodTimeline() throws Exception {
PlayerWrapper playerWrapper = new PlayerWrapper();
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(false, false, 0));
Object manifest = new Object();
MediaSource mediaSource = new FakeMediaSource(timeline, manifest, TEST_VIDEO_FORMAT);
FakeRenderer renderer = new FakeRenderer(TEST_VIDEO_FORMAT);
playerWrapper.setup(mediaSource, renderer);
playerWrapper.blockUntilEnded(TIMEOUT_MS);
assertEquals(0, playerWrapper.positionDiscontinuityCount);
assertEquals(1, renderer.formatReadCount);
assertEquals(1, renderer.bufferReadCount);
assertTrue(renderer.isEnded);
assertEquals(timeline, playerWrapper.timeline);
assertEquals(manifest, playerWrapper.manifest);
assertEquals(new TrackGroupArray(new TrackGroup(TEST_VIDEO_FORMAT)), playerWrapper.trackGroups);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class ExoPlayerTest method testReadAheadToEndDoesNotResetRenderer.
/**
* Tests that the player does not unnecessarily reset renderers when playing a multi-period
* source.
*/
public void testReadAheadToEndDoesNotResetRenderer() throws Exception {
final PlayerWrapper playerWrapper = new PlayerWrapper();
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(false, false, 10), new TimelineWindowDefinition(false, false, 10), new TimelineWindowDefinition(false, false, 10));
MediaSource mediaSource = new FakeMediaSource(timeline, null, TEST_VIDEO_FORMAT, TEST_AUDIO_FORMAT);
FakeRenderer videoRenderer = new FakeRenderer(TEST_VIDEO_FORMAT);
FakeMediaClockRenderer audioRenderer = new FakeMediaClockRenderer(TEST_AUDIO_FORMAT) {
@Override
public long getPositionUs() {
// TODO: Avoid hard-coding ExoPlayerImplInternal.RENDERER_TIMESTAMP_OFFSET_US.
return isCurrentStreamFinal() ? 60000030 : 60000000;
}
@Override
public boolean isEnded() {
// Allow playback to end once the final period is playing.
return playerWrapper.positionDiscontinuityCount == 2;
}
};
playerWrapper.setup(mediaSource, videoRenderer, audioRenderer);
playerWrapper.blockUntilEnded(TIMEOUT_MS);
assertEquals(2, playerWrapper.positionDiscontinuityCount);
assertEquals(1, audioRenderer.positionResetCount);
assertTrue(videoRenderer.isEnded);
assertTrue(audioRenderer.isEnded);
assertEquals(timeline, playerWrapper.timeline);
assertNull(playerWrapper.manifest);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
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 com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class TimelineTest method roundTripViaBundle_ofTimeline_yieldsEqualInstanceExceptIdsAndManifest.
@Test
public void roundTripViaBundle_ofTimeline_yieldsEqualInstanceExceptIdsAndManifest() {
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
2, /* id= */
new Object(), /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
2, /* defaultPositionUs= */
22, /* windowOffsetInFirstPeriodUs= */
222, ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setMediaId("mediaId2").build()), new TimelineWindowDefinition(/* periodCount= */
3, /* id= */
new Object(), /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
3, /* defaultPositionUs= */
33, /* windowOffsetInFirstPeriodUs= */
333, ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setMediaId("mediaId3").build()));
Timeline restoredTimeline = Timeline.CREATOR.fromBundle(timeline.toBundle());
TimelineAsserts.assertEqualsExceptIdsAndManifest(/* expectedTimeline= */
timeline, /* actualTimeline= */
restoredTimeline);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
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);
}
Aggregations