Search in sources :

Example 1 with MediaSourceTestRunner

use of com.google.android.exoplayer2.testutil.MediaSourceTestRunner 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();
}
Also used : MediaSourceTestRunner(com.google.android.exoplayer2.testutil.MediaSourceTestRunner) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DefaultShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder.DefaultShuffleOrder) Test(org.junit.Test)

Example 2 with MediaSourceTestRunner

use of com.google.android.exoplayer2.testutil.MediaSourceTestRunner 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);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaSourceTestRunner(com.google.android.exoplayer2.testutil.MediaSourceTestRunner) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DefaultShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder.DefaultShuffleOrder) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 3 with MediaSourceTestRunner

use of com.google.android.exoplayer2.testutil.MediaSourceTestRunner 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();
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaSourceTestRunner(com.google.android.exoplayer2.testutil.MediaSourceTestRunner) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DefaultShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder.DefaultShuffleOrder) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 4 with MediaSourceTestRunner

use of com.google.android.exoplayer2.testutil.MediaSourceTestRunner in project ExoPlayer by google.

the class LoopingMediaSourceTest method testMediaPeriodCreation.

/**
 * Wraps the specified timeline in a {@link LoopingMediaSource} and asserts that all periods of
 * the looping timeline can be created and prepared.
 */
private static void testMediaPeriodCreation(Timeline timeline, int loopCount) throws Exception {
    FakeMediaSource fakeMediaSource = new FakeMediaSource(timeline);
    LoopingMediaSource mediaSource = new LoopingMediaSource(fakeMediaSource, loopCount);
    MediaSourceTestRunner testRunner = new MediaSourceTestRunner(mediaSource, null);
    try {
        testRunner.prepareSource();
        testRunner.assertPrepareAndReleaseAllPeriods();
        testRunner.releaseSource();
    } finally {
        testRunner.release();
    }
}
Also used : MediaSourceTestRunner(com.google.android.exoplayer2.testutil.MediaSourceTestRunner) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource)

Example 5 with MediaSourceTestRunner

use of com.google.android.exoplayer2.testutil.MediaSourceTestRunner in project ExoPlayer by google.

the class MergingMediaSourceTest method prepareMergingMediaSource.

/**
 * Wraps the specified timelines in a {@link MergingMediaSource}, prepares it and returns the
 * merged timeline.
 */
private static Timeline prepareMergingMediaSource(boolean clipDurations, Timeline... timelines) throws IOException {
    FakeMediaSource[] mediaSources = new FakeMediaSource[timelines.length];
    for (int i = 0; i < timelines.length; i++) {
        mediaSources[i] = new FakeMediaSource(timelines[i]);
    }
    MergingMediaSource mergingMediaSource = new MergingMediaSource(/* adjustPeriodTimeOffsets= */
    false, clipDurations, mediaSources);
    MediaSourceTestRunner testRunner = new MediaSourceTestRunner(mergingMediaSource, /* allocator= */
    null);
    try {
        Timeline timeline = testRunner.prepareSource();
        testRunner.releaseSource();
        for (FakeMediaSource mediaSource : mediaSources) {
            mediaSource.assertReleased();
        }
        return timeline;
    } finally {
        testRunner.release();
    }
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaSourceTestRunner(com.google.android.exoplayer2.testutil.MediaSourceTestRunner) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource)

Aggregations

MediaSourceTestRunner (com.google.android.exoplayer2.testutil.MediaSourceTestRunner)11 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)8 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)7 Timeline (com.google.android.exoplayer2.Timeline)6 Test (org.junit.Test)6 DefaultShuffleOrder (com.google.android.exoplayer2.source.ShuffleOrder.DefaultShuffleOrder)4 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)3 FakeShuffleOrder (com.google.android.exoplayer2.testutil.FakeShuffleOrder)2 PlaceholderTimeline (com.google.android.exoplayer2.source.MaskingMediaSource.PlaceholderTimeline)1 Before (org.junit.Before)1