use of com.google.android.exoplayer2.testutil.FakeMediaSource in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method childSourceIsNotPreparedWithLazyPreparation.
@Test
public void childSourceIsNotPreparedWithLazyPreparation() throws IOException {
FakeMediaSource[] childSources = createMediaSources(/* count= */
2);
mediaSource = new ConcatenatingMediaSource(/* isAtomic= */
false, /* useLazyPreparation= */
true, new DefaultShuffleOrder(0), childSources);
testRunner = new MediaSourceTestRunner(mediaSource, /* allocator= */
null);
testRunner.prepareSource();
assertThat(childSources[0].isPrepared()).isFalse();
assertThat(childSources[1].isPrepared()).isFalse();
}
use of com.google.android.exoplayer2.testutil.FakeMediaSource in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method periodCreationWithAds.
@Test
public void periodCreationWithAds() throws IOException, InterruptedException {
// Create concatenated media source with ad child source.
Timeline timelineContentOnly = new FakeTimeline(new TimelineWindowDefinition(2, 111, true, false, 10 * C.MICROS_PER_SECOND));
Timeline timelineWithAds = new FakeTimeline(new TimelineWindowDefinition(2, 222, true, false, 10 * C.MICROS_PER_SECOND, FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
1, /* adGroupTimesUs=... */
0)));
FakeMediaSource mediaSourceContentOnly = new FakeMediaSource(timelineContentOnly);
FakeMediaSource mediaSourceWithAds = new FakeMediaSource(timelineWithAds);
mediaSource.addMediaSource(mediaSourceContentOnly);
mediaSource.addMediaSource(mediaSourceWithAds);
Timeline timeline = testRunner.prepareSource();
// Assert the timeline contains ad groups.
TimelineAsserts.assertAdGroupCounts(timeline, 0, 0, 1, 1);
// Create all periods and assert period creation of child media sources has been called.
testRunner.assertPrepareAndReleaseAllPeriods();
Object timelineContentOnlyPeriodUid0 = timelineContentOnly.getUidOfPeriod(/* periodIndex= */
0);
Object timelineContentOnlyPeriodUid1 = timelineContentOnly.getUidOfPeriod(/* periodIndex= */
1);
Object timelineWithAdsPeriodUid0 = timelineWithAds.getUidOfPeriod(/* periodIndex= */
0);
Object timelineWithAdsPeriodUid1 = timelineWithAds.getUidOfPeriod(/* periodIndex= */
1);
mediaSourceContentOnly.assertMediaPeriodCreated(new MediaPeriodId(timelineContentOnlyPeriodUid0, /* windowSequenceNumber= */
0));
mediaSourceContentOnly.assertMediaPeriodCreated(new MediaPeriodId(timelineContentOnlyPeriodUid1, /* windowSequenceNumber= */
0));
mediaSourceWithAds.assertMediaPeriodCreated(new MediaPeriodId(timelineWithAdsPeriodUid0, /* windowSequenceNumber= */
1));
mediaSourceWithAds.assertMediaPeriodCreated(new MediaPeriodId(timelineWithAdsPeriodUid1, /* windowSequenceNumber= */
1));
mediaSourceWithAds.assertMediaPeriodCreated(new MediaPeriodId(timelineWithAdsPeriodUid0, /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
1));
mediaSourceWithAds.assertMediaPeriodCreated(new MediaPeriodId(timelineWithAdsPeriodUid1, /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
1));
testRunner.assertCompletedManifestLoads(0, 1);
assertCompletedAllMediaPeriodLoads(timeline);
}
use of com.google.android.exoplayer2.testutil.FakeMediaSource in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method playlistChangesBeforePreparation.
@Test
public void playlistChangesBeforePreparation() throws IOException, InterruptedException {
FakeMediaSource[] childSources = createMediaSources(4);
mediaSource.addMediaSource(childSources[0]);
mediaSource.addMediaSource(childSources[1]);
mediaSource.addMediaSource(0, childSources[2]);
mediaSource.moveMediaSource(0, 2);
mediaSource.removeMediaSource(0);
mediaSource.moveMediaSource(1, 0);
mediaSource.addMediaSource(1, childSources[3]);
testRunner.assertNoTimelineChange();
Timeline timeline = testRunner.prepareSource();
TimelineAsserts.assertPeriodCounts(timeline, 3, 4, 2);
TimelineAsserts.assertWindowTags(timeline, 333, 444, 222);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, 1, 2, C.INDEX_UNSET);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, C.INDEX_UNSET, 0, 1);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, true, C.INDEX_UNSET, 0, 1);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, true, 1, 2, C.INDEX_UNSET);
testRunner.assertPrepareAndReleaseAllPeriods();
testRunner.assertCompletedManifestLoads(0, 1, 2);
assertCompletedAllMediaPeriodLoads(timeline);
testRunner.releaseSource();
for (int i = 1; i < 4; i++) {
childSources[i].assertReleased();
}
}
use of com.google.android.exoplayer2.testutil.FakeMediaSource 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.testutil.FakeMediaSource 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);
}
Aggregations