Search in sources :

Example 1 with DefaultShuffleOrder

use of androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder 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 DefaultShuffleOrder

use of androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder 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 DefaultShuffleOrder

use of androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder 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 DefaultShuffleOrder

use of androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder in project media by androidx.

the class ShuffleOrderTest method defaultShuffleOrderSideloaded.

@Test
public void defaultShuffleOrderSideloaded() {
    int[] shuffledIndices = new int[] { 2, 1, 0, 4, 3 };
    ShuffleOrder shuffleOrder = new DefaultShuffleOrder(shuffledIndices, RANDOM_SEED);
    assertThat(shuffleOrder.getFirstIndex()).isEqualTo(2);
    assertThat(shuffleOrder.getLastIndex()).isEqualTo(3);
    for (int i = 0; i < 4; i++) {
        assertThat(shuffleOrder.getNextIndex(shuffledIndices[i])).isEqualTo(shuffledIndices[i + 1]);
    }
    assertThat(shuffleOrder.getNextIndex(3)).isEqualTo(C.INDEX_UNSET);
    for (int i = 4; i > 0; i--) {
        assertThat(shuffleOrder.getPreviousIndex(shuffledIndices[i])).isEqualTo(shuffledIndices[i - 1]);
    }
    assertThat(shuffleOrder.getPreviousIndex(2)).isEqualTo(C.INDEX_UNSET);
}
Also used : DefaultShuffleOrder(androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder) UnshuffledShuffleOrder(androidx.media3.exoplayer.source.ShuffleOrder.UnshuffledShuffleOrder) DefaultShuffleOrder(androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder) Test(org.junit.Test)

Example 5 with DefaultShuffleOrder

use of androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder in project media by androidx.

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

Aggregations

DefaultShuffleOrder (androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder)6 Test (org.junit.Test)6 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)4 MediaSourceTestRunner (androidx.media3.test.utils.MediaSourceTestRunner)4 Timeline (androidx.media3.common.Timeline)2 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)2 FakeTimeline (androidx.media3.test.utils.FakeTimeline)2 UnshuffledShuffleOrder (androidx.media3.exoplayer.source.ShuffleOrder.UnshuffledShuffleOrder)1