Search in sources :

Example 1 with MediaSourceTestRunner

use of androidx.media3.test.utils.MediaSourceTestRunner in project media by androidx.

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 : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) MediaSourceTestRunner(androidx.media3.test.utils.MediaSourceTestRunner) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) DefaultShuffleOrder(androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 2 with MediaSourceTestRunner

use of androidx.media3.test.utils.MediaSourceTestRunner in project media by androidx.

the class ConcatenatingMediaSourceTest method removeUnpreparedChildSourceWithLazyPreparation.

@Test
public void removeUnpreparedChildSourceWithLazyPreparation() 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();
    // Check that removal doesn't throw even though the child sources are unprepared.
    mediaSource.removeMediaSource(0);
}
Also used : MediaSourceTestRunner(androidx.media3.test.utils.MediaSourceTestRunner) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) DefaultShuffleOrder(androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder) Test(org.junit.Test)

Example 3 with MediaSourceTestRunner

use of androidx.media3.test.utils.MediaSourceTestRunner in project media by androidx.

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 : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) MediaSourceTestRunner(androidx.media3.test.utils.MediaSourceTestRunner) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) DefaultShuffleOrder(androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 4 with MediaSourceTestRunner

use of androidx.media3.test.utils.MediaSourceTestRunner in project media by androidx.

the class LoopingMediaSourceTest method getLoopingTimeline.

/**
 * Wraps the specified timeline in a {@link LoopingMediaSource} and returns the looping timeline.
 */
private static Timeline getLoopingTimeline(Timeline timeline, int loopCount) throws IOException {
    FakeMediaSource fakeMediaSource = new FakeMediaSource(timeline);
    LoopingMediaSource mediaSource = new LoopingMediaSource(fakeMediaSource, loopCount);
    MediaSourceTestRunner testRunner = new MediaSourceTestRunner(mediaSource, null);
    try {
        Timeline loopingTimeline = testRunner.prepareSource();
        testRunner.releaseSource();
        fakeMediaSource.assertReleased();
        return loopingTimeline;
    } finally {
        testRunner.release();
    }
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) MediaSourceTestRunner(androidx.media3.test.utils.MediaSourceTestRunner) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource)

Example 5 with MediaSourceTestRunner

use of androidx.media3.test.utils.MediaSourceTestRunner in project media by androidx.

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(androidx.media3.test.utils.MediaSourceTestRunner) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource)

Aggregations

MediaSourceTestRunner (androidx.media3.test.utils.MediaSourceTestRunner)11 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)8 FakeTimeline (androidx.media3.test.utils.FakeTimeline)7 Timeline (androidx.media3.common.Timeline)6 Test (org.junit.Test)6 DefaultShuffleOrder (androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder)4 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)3 FakeShuffleOrder (androidx.media3.test.utils.FakeShuffleOrder)2 PlaceholderTimeline (androidx.media3.exoplayer.source.MaskingMediaSource.PlaceholderTimeline)1 Before (org.junit.Before)1