Search in sources :

Example 81 with Timeline

use of com.google.android.exoplayer2.Timeline 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 82 with Timeline

use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.

the class ConcatenatingMediaSourceTest method dynamicChangeOfEmptyTimelines.

@Test
public void dynamicChangeOfEmptyTimelines() throws IOException {
    FakeMediaSource[] childSources = new FakeMediaSource[] { new FakeMediaSource(Timeline.EMPTY), new FakeMediaSource(Timeline.EMPTY), new FakeMediaSource(Timeline.EMPTY) };
    Timeline nonEmptyTimeline = new FakeTimeline(/* windowCount = */
    1);
    mediaSource.addMediaSources(Arrays.asList(childSources));
    Timeline timeline = testRunner.prepareSource();
    TimelineAsserts.assertEmpty(timeline);
    childSources[0].setNewSourceInfo(nonEmptyTimeline);
    timeline = testRunner.assertTimelineChangeBlocking();
    TimelineAsserts.assertPeriodCounts(timeline, 1);
    childSources[2].setNewSourceInfo(nonEmptyTimeline);
    timeline = testRunner.assertTimelineChangeBlocking();
    TimelineAsserts.assertPeriodCounts(timeline, 1, 1);
    childSources[1].setNewSourceInfo(nonEmptyTimeline);
    timeline = testRunner.assertTimelineChangeBlocking();
    TimelineAsserts.assertPeriodCounts(timeline, 1, 1, 1);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Test(org.junit.Test)

Example 83 with Timeline

use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.

the class ConcatenatingMediaSourceTest method customCallbackAfterPreparationRemove.

@Test
public void customCallbackAfterPreparationRemove() throws Exception {
    DummyMainThread testThread = new DummyMainThread();
    try {
        testRunner.prepareSource();
        testThread.runOnMainThread(() -> mediaSource.addMediaSource(createFakeMediaSource()));
        testRunner.assertTimelineChangeBlocking();
        final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
        testThread.runOnMainThread(() -> mediaSource.removeMediaSource(/* index */
        0, Util.createHandlerForCurrentLooper(), timelineGrabber));
        Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
        assertThat(timeline.getWindowCount()).isEqualTo(0);
    } 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 84 with Timeline

use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.

the class ConcatenatingMediaSourceTest method nestedTimeline.

@Test
public void nestedTimeline() throws IOException {
    ConcatenatingMediaSource nestedSource1 = new ConcatenatingMediaSource(/* isAtomic= */
    false, new FakeShuffleOrder(0));
    ConcatenatingMediaSource nestedSource2 = new ConcatenatingMediaSource(/* isAtomic= */
    true, new FakeShuffleOrder(0));
    mediaSource.addMediaSource(nestedSource1);
    mediaSource.addMediaSource(nestedSource2);
    testRunner.prepareSource();
    FakeMediaSource[] childSources = createMediaSources(4);
    nestedSource1.addMediaSource(childSources[0]);
    testRunner.assertTimelineChangeBlocking();
    nestedSource1.addMediaSource(childSources[1]);
    testRunner.assertTimelineChangeBlocking();
    nestedSource2.addMediaSource(childSources[2]);
    testRunner.assertTimelineChangeBlocking();
    nestedSource2.addMediaSource(childSources[3]);
    Timeline timeline = testRunner.assertTimelineChangeBlocking();
    TimelineAsserts.assertWindowTags(timeline, 111, 222, 333, 444);
    TimelineAsserts.assertPeriodCounts(timeline, 1, 2, 3, 4);
    TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
    false, C.INDEX_UNSET, 0, 1, 2);
    TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
    false, 0, 1, 3, 2);
    TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
    false, 3, 0, 1, 2);
    TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
    false, 1, 2, 3, C.INDEX_UNSET);
    TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
    false, 0, 1, 3, 2);
    TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
    false, 1, 2, 3, 0);
    TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
    true, 1, 3, C.INDEX_UNSET, 2);
    TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
    true, 0, 1, 3, 2);
    TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
    true, 1, 3, 0, 2);
    TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
    true, C.INDEX_UNSET, 0, 3, 1);
    TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
    true, 0, 1, 3, 2);
    TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
    true, 2, 0, 3, 1);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeShuffleOrder(com.google.android.exoplayer2.testutil.FakeShuffleOrder) Test(org.junit.Test)

Example 85 with Timeline

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

Aggregations

Test (org.junit.Test)347 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)246 Timeline (com.google.android.exoplayer2.Timeline)163 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)140 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)125 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)110 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)109 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)89 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)85 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)79 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)74 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)60 Format (com.google.android.exoplayer2.Format)49 MediaSource (com.google.android.exoplayer2.source.MediaSource)47 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)44 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)38 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)36 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)35 MediaItem (com.google.android.exoplayer2.MediaItem)34 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)33