use of com.google.android.exoplayer2.source.MediaPeriod in project ExoPlayer by google.
the class MediaPeriodAsserts method prepareAndGetTrackGroups.
private static TrackGroupArray prepareAndGetTrackGroups(MediaPeriod mediaPeriod) {
AtomicReference<TrackGroupArray> trackGroupArray = new AtomicReference<>();
DummyMainThread testThread = new DummyMainThread();
ConditionVariable preparedCondition = new ConditionVariable();
testThread.runOnMainThread(() -> mediaPeriod.prepare(new Callback() {
@Override
public void onPrepared(MediaPeriod mediaPeriod) {
trackGroupArray.set(mediaPeriod.getTrackGroups());
preparedCondition.open();
}
@Override
public void onContinueLoadingRequested(MediaPeriod source) {
// Ignore.
}
}, /* positionUs= */
0));
try {
preparedCondition.block();
} catch (InterruptedException e) {
// Ignore.
}
testThread.release();
return trackGroupArray.get();
}
use of com.google.android.exoplayer2.source.MediaPeriod in project ExoPlayer by google.
the class MediaPeriodAsserts method assertTrackGroups.
/**
* Prepares the {@link MediaPeriod} and asserts that it provides the specified track groups.
*
* @param mediaPeriod The {@link MediaPeriod} to test.
* @param expectedGroups The expected track groups.
*/
public static void assertTrackGroups(MediaPeriod mediaPeriod, TrackGroupArray expectedGroups) {
TrackGroupArray actualGroups = prepareAndGetTrackGroups(mediaPeriod);
assertThat(actualGroups).isEqualTo(expectedGroups);
}
use of com.google.android.exoplayer2.source.MediaPeriod in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method removeChildSourceWithActiveMediaPeriod.
@Test
public void removeChildSourceWithActiveMediaPeriod() throws IOException {
FakeMediaSource childSource = createFakeMediaSource();
mediaSource.addMediaSource(childSource);
Timeline timeline = testRunner.prepareSource();
MediaPeriod mediaPeriod = testRunner.createPeriod(new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0));
mediaSource.removeMediaSource(/* index= */
0);
testRunner.assertTimelineChangeBlocking();
testRunner.releasePeriod(mediaPeriod);
childSource.assertReleased();
testRunner.releaseSource();
}
use of com.google.android.exoplayer2.source.MediaPeriod in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method childTimelineChangeWithActiveMediaPeriod.
@Test
public void childTimelineChangeWithActiveMediaPeriod() throws IOException {
FakeMediaSource[] nestedChildSources = createMediaSources(/* count= */
2);
ConcatenatingMediaSource childSource = new ConcatenatingMediaSource(nestedChildSources);
mediaSource.addMediaSource(childSource);
Timeline timeline = testRunner.prepareSource();
MediaPeriod mediaPeriod = testRunner.createPeriod(new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
1), /* windowSequenceNumber= */
0));
childSource.moveMediaSource(/* currentIndex= */
0, /* newIndex= */
1);
timeline = testRunner.assertTimelineChangeBlocking();
testRunner.preparePeriod(mediaPeriod, /* positionUs= */
0);
testRunner.assertCompletedMediaPeriodLoads(new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0));
}
use of com.google.android.exoplayer2.source.MediaPeriod in project ExoPlayer by google.
the class AdsMediaSourceTest method releasePeriod_releasesChildMediaPeriodsAndSources.
@Test
public void releasePeriod_releasesChildMediaPeriodsAndSources() {
contentMediaSource.setNewSourceInfo(CONTENT_TIMELINE);
MediaPeriod prerollAdMediaPeriod = adsMediaSource.createPeriod(new MediaPeriodId(CONTENT_PERIOD_UID, /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
0), mock(Allocator.class), /* startPositionUs= */
0);
prerollAdMediaSource.setNewSourceInfo(PREROLL_AD_TIMELINE);
shadowOf(Looper.getMainLooper()).idle();
MediaPeriod contentMediaPeriod = adsMediaSource.createPeriod(new MediaPeriodId(CONTENT_PERIOD_UID, /* windowSequenceNumber= */
0), mock(Allocator.class), /* startPositionUs= */
0);
adsMediaSource.releasePeriod(prerollAdMediaPeriod);
prerollAdMediaSource.assertReleased();
adsMediaSource.releasePeriod(contentMediaPeriod);
adsMediaSource.releaseSource(mockMediaSourceCaller);
shadowOf(Looper.getMainLooper()).idle();
prerollAdMediaSource.assertReleased();
contentMediaSource.assertReleased();
}
Aggregations