use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method childSourceWithLazyPreparationOnlyPreparesSourceOnce.
@Test
public void childSourceWithLazyPreparationOnlyPreparesSourceOnce() throws IOException {
FakeMediaSource[] childSources = createMediaSources(/* count= */
2);
mediaSource = new ConcatenatingMediaSource(/* isAtomic= */
false, /* useLazyPreparation= */
true, new DefaultShuffleOrder(0), childSources);
testRunner = new MediaSourceTestRunner(mediaSource, /* allocator= */
null);
Timeline timeline = testRunner.prepareSource();
// The lazy preparation must only be triggered once, even if we create multiple periods from
// the media source. FakeMediaSource.prepareSource asserts that it's not called twice, so
// creating two periods shouldn't throw.
MediaPeriodId mediaPeriodId = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0);
testRunner.createPeriod(mediaPeriodId);
testRunner.createPeriod(mediaPeriodId);
}
use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method dynamicChangeOfEmptyTimelines.
@Test
public void dynamicChangeOfEmptyTimelines() throws IOException {
FakeMediaSource[] childSources = new FakeMediaSource[] { new FakeMediaSource(Timeline.EMPTY), new FakeMediaSource(Timeline.EMPTY), new FakeMediaSource(Timeline.EMPTY) };
Timeline nonEmptyTimeline = new FakeTimeline(/* windowCount = */
1);
mediaSource.addMediaSources(Arrays.asList(childSources));
Timeline timeline = testRunner.prepareSource();
TimelineAsserts.assertEmpty(timeline);
childSources[0].setNewSourceInfo(nonEmptyTimeline);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 1);
childSources[2].setNewSourceInfo(nonEmptyTimeline);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 1, 1);
childSources[1].setNewSourceInfo(nonEmptyTimeline);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 1, 1, 1);
}
use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method customCallbackAfterPreparationRemove.
@Test
public void customCallbackAfterPreparationRemove() throws Exception {
DummyMainThread testThread = new DummyMainThread();
try {
testRunner.prepareSource();
testThread.runOnMainThread(() -> mediaSource.addMediaSource(createFakeMediaSource()));
testRunner.assertTimelineChangeBlocking();
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
testThread.runOnMainThread(() -> mediaSource.removeMediaSource(/* index */
0, Util.createHandlerForCurrentLooper(), timelineGrabber));
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
assertThat(timeline.getWindowCount()).isEqualTo(0);
} finally {
testThread.release();
}
}
use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method nestedTimeline.
@Test
public void nestedTimeline() throws IOException {
ConcatenatingMediaSource nestedSource1 = new ConcatenatingMediaSource(/* isAtomic= */
false, new FakeShuffleOrder(0));
ConcatenatingMediaSource nestedSource2 = new ConcatenatingMediaSource(/* isAtomic= */
true, new FakeShuffleOrder(0));
mediaSource.addMediaSource(nestedSource1);
mediaSource.addMediaSource(nestedSource2);
testRunner.prepareSource();
FakeMediaSource[] childSources = createMediaSources(4);
nestedSource1.addMediaSource(childSources[0]);
testRunner.assertTimelineChangeBlocking();
nestedSource1.addMediaSource(childSources[1]);
testRunner.assertTimelineChangeBlocking();
nestedSource2.addMediaSource(childSources[2]);
testRunner.assertTimelineChangeBlocking();
nestedSource2.addMediaSource(childSources[3]);
Timeline timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertWindowTags(timeline, 111, 222, 333, 444);
TimelineAsserts.assertPeriodCounts(timeline, 1, 2, 3, 4);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
false, C.INDEX_UNSET, 0, 1, 2);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
false, 0, 1, 3, 2);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
false, 3, 0, 1, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
false, 1, 2, 3, C.INDEX_UNSET);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
false, 0, 1, 3, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
false, 1, 2, 3, 0);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
true, 1, 3, C.INDEX_UNSET, 2);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
true, 0, 1, 3, 2);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
true, 1, 3, 0, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
true, C.INDEX_UNSET, 0, 3, 1);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
true, 0, 1, 3, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
true, 2, 0, 3, 1);
}
use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method childSourceIsPreparedWithLazyPreparationAfterPeriodCreation.
@Test
public void childSourceIsPreparedWithLazyPreparationAfterPeriodCreation() throws IOException {
FakeMediaSource[] childSources = createMediaSources(/* count= */
2);
mediaSource = new ConcatenatingMediaSource(/* isAtomic= */
false, /* useLazyPreparation= */
true, new DefaultShuffleOrder(0), childSources);
testRunner = new MediaSourceTestRunner(mediaSource, /* allocator= */
null);
Timeline timeline = testRunner.prepareSource();
testRunner.createPeriod(new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0));
assertThat(childSources[0].isPrepared()).isTrue();
assertThat(childSources[1].isPrepared()).isFalse();
}
Aggregations