Search in sources :

Example 26 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource 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 27 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource 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 28 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource 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 29 with MediaSource

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

Example 30 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource 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)

Aggregations

Test (org.junit.Test)182 MediaSource (com.google.android.exoplayer2.source.MediaSource)117 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)117 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)74 MediaItem (com.google.android.exoplayer2.MediaItem)70 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)70 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)69 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)60 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)51 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)51 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)51 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)50 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)50 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)45 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)39 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)39 Timeline (com.google.android.exoplayer2.Timeline)35 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)34 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)28 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)25