use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method customCallbackAfterPreparationMove.
@Test
public void customCallbackAfterPreparationMove() throws Exception {
DummyMainThread testThread = new DummyMainThread();
try {
testRunner.prepareSource();
testThread.runOnMainThread(() -> mediaSource.addMediaSources(Arrays.asList(new MediaSource[] { createFakeMediaSource(), createFakeMediaSource() })));
testRunner.assertTimelineChangeBlocking();
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
testThread.runOnMainThread(() -> mediaSource.moveMediaSource(/* currentIndex= */
1, /* newIndex= */
0, Util.createHandlerForCurrentLooper(), timelineGrabber));
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
assertThat(timeline.getWindowCount()).isEqualTo(2);
} finally {
testThread.release();
}
}
use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method duplicateNestedMediaSources.
@Test
public void duplicateNestedMediaSources() throws IOException, InterruptedException {
Timeline childTimeline = new FakeTimeline();
FakeMediaSource childSource = new FakeMediaSource(childTimeline);
ConcatenatingMediaSource nestedConcatenation = new ConcatenatingMediaSource();
testRunner.prepareSource();
mediaSource.addMediaSources(Arrays.asList(childSource, nestedConcatenation, nestedConcatenation));
testRunner.assertTimelineChangeBlocking();
nestedConcatenation.addMediaSource(childSource);
testRunner.assertTimelineChangeBlocking();
nestedConcatenation.addMediaSource(childSource);
Timeline timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 1, 1, 1, 1, 1);
testRunner.assertPrepareAndReleaseAllPeriods();
Object childPeriodUid = childTimeline.getUidOfPeriod(/* periodIndex= */
0);
assertThat(childSource.getCreatedMediaPeriods()).containsAtLeast(new MediaPeriodId(childPeriodUid, /* windowSequenceNumber= */
0), new MediaPeriodId(childPeriodUid, /* windowSequenceNumber= */
1), new MediaPeriodId(childPeriodUid, /* windowSequenceNumber= */
2), new MediaPeriodId(childPeriodUid, /* windowSequenceNumber= */
3), new MediaPeriodId(childPeriodUid, /* windowSequenceNumber= */
4));
// Assert that only one manifest load is needed because the source is reused.
testRunner.assertCompletedManifestLoads(/* windowIndices=... */
0);
assertCompletedAllMediaPeriodLoads(timeline);
testRunner.releaseSource();
childSource.assertReleased();
}
use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method playlistChangesAfterPreparation.
@Test
public void playlistChangesAfterPreparation() throws IOException, InterruptedException {
Timeline timeline = testRunner.prepareSource();
TimelineAsserts.assertEmpty(timeline);
FakeMediaSource[] childSources = createMediaSources(7);
// Add first source.
mediaSource.addMediaSource(childSources[0]);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 1);
TimelineAsserts.assertWindowTags(timeline, 111);
// Add at front of queue.
mediaSource.addMediaSource(0, childSources[1]);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 2, 1);
TimelineAsserts.assertWindowTags(timeline, 222, 111);
// Add at back of queue.
mediaSource.addMediaSource(childSources[2]);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 2, 1, 3);
TimelineAsserts.assertWindowTags(timeline, 222, 111, 333);
// Add in the middle.
mediaSource.addMediaSource(1, childSources[3]);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 2, 4, 1, 3);
TimelineAsserts.assertWindowTags(timeline, 222, 444, 111, 333);
// Add bulk.
mediaSource.addMediaSources(3, Arrays.asList(childSources[4], childSources[5], childSources[6]));
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 2, 4, 1, 5, 6, 7, 3);
TimelineAsserts.assertWindowTags(timeline, 222, 444, 111, 555, 666, 777, 333);
// Move sources.
mediaSource.moveMediaSource(2, 3);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 2, 4, 5, 1, 6, 7, 3);
TimelineAsserts.assertWindowTags(timeline, 222, 444, 555, 111, 666, 777, 333);
mediaSource.moveMediaSource(3, 2);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 2, 4, 1, 5, 6, 7, 3);
TimelineAsserts.assertWindowTags(timeline, 222, 444, 111, 555, 666, 777, 333);
mediaSource.moveMediaSource(0, 6);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 4, 1, 5, 6, 7, 3, 2);
TimelineAsserts.assertWindowTags(timeline, 444, 111, 555, 666, 777, 333, 222);
mediaSource.moveMediaSource(6, 0);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 2, 4, 1, 5, 6, 7, 3);
TimelineAsserts.assertWindowTags(timeline, 222, 444, 111, 555, 666, 777, 333);
// Remove in the middle.
mediaSource.removeMediaSource(3);
testRunner.assertTimelineChangeBlocking();
mediaSource.removeMediaSource(3);
testRunner.assertTimelineChangeBlocking();
mediaSource.removeMediaSource(3);
testRunner.assertTimelineChangeBlocking();
mediaSource.removeMediaSource(1);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 2, 1, 3);
TimelineAsserts.assertWindowTags(timeline, 222, 111, 333);
for (int i = 3; i <= 6; i++) {
childSources[i].assertReleased();
}
// Assert the correct child source preparation load events have been returned (with the
// respective window index at the time of preparation).
testRunner.assertCompletedManifestLoads(0, 0, 2, 1, 3, 4, 5);
// Assert correct next and previous indices behavior after some insertions and removals.
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, 1, 2, C.INDEX_UNSET);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0, 1, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 1, 2, 0);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, C.INDEX_UNSET, 0, 1);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0, 1, 2);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 2, 0, 1);
assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0);
assertThat(timeline.getLastWindowIndex(false)).isEqualTo(timeline.getWindowCount() - 1);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, true, C.INDEX_UNSET, 0, 1);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, true, 1, 2, C.INDEX_UNSET);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 1, 2, 0);
assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(timeline.getWindowCount() - 1);
assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);
// Assert all periods can be prepared and the respective load events are returned.
testRunner.assertPrepareAndReleaseAllPeriods();
assertCompletedAllMediaPeriodLoads(timeline);
// Remove at front of queue.
mediaSource.removeMediaSource(0);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 1, 3);
TimelineAsserts.assertWindowTags(timeline, 111, 333);
childSources[1].assertReleased();
// Remove at back of queue.
mediaSource.removeMediaSource(1);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 1);
TimelineAsserts.assertWindowTags(timeline, 111);
childSources[2].assertReleased();
// Remove last source.
mediaSource.removeMediaSource(0);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertEmpty(timeline);
childSources[3].assertReleased();
}
use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method customCallbackAfterPreparationSetShuffleOrder.
@Test
public void customCallbackAfterPreparationSetShuffleOrder() throws Exception {
DummyMainThread testThread = new DummyMainThread();
try {
mediaSource.addMediaSources(Arrays.asList(createFakeMediaSource(), createFakeMediaSource(), createFakeMediaSource()));
testRunner.prepareSource();
TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
testThread.runOnMainThread(() -> mediaSource.setShuffleOrder(new ShuffleOrder.UnshuffledShuffleOrder(/* length= */
3), Util.createHandlerForCurrentLooper(), timelineGrabber));
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
assertThat(timeline.getFirstWindowIndex(/* shuffleModeEnabled= */
true)).isEqualTo(0);
} finally {
testThread.release();
}
}
use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method assertCompletedAllMediaPeriodLoads.
private void assertCompletedAllMediaPeriodLoads(Timeline timeline) {
Timeline.Period period = new Timeline.Period();
Timeline.Window window = new Timeline.Window();
ArrayList<MediaPeriodId> expectedMediaPeriodIds = new ArrayList<>();
for (int windowIndex = 0; windowIndex < timeline.getWindowCount(); windowIndex++) {
timeline.getWindow(windowIndex, window);
for (int periodIndex = window.firstPeriodIndex; periodIndex <= window.lastPeriodIndex; periodIndex++) {
timeline.getPeriod(periodIndex, period);
Object periodUid = timeline.getUidOfPeriod(periodIndex);
expectedMediaPeriodIds.add(new MediaPeriodId(periodUid, windowIndex));
for (int adGroupIndex = 0; adGroupIndex < period.getAdGroupCount(); adGroupIndex++) {
for (int adIndex = 0; adIndex < period.getAdCountInAdGroup(adGroupIndex); adIndex++) {
expectedMediaPeriodIds.add(new MediaPeriodId(periodUid, adGroupIndex, adIndex, windowIndex));
}
}
}
}
testRunner.assertCompletedMediaPeriodLoads(expectedMediaPeriodIds.toArray(new MediaPeriodId[0]));
}
Aggregations