Search in sources :

Example 1 with FakeTimeline

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

the class ExoPlayerTest method testPlaySinglePeriodTimeline.

/**
   * Tests playback of a source that exposes a single period.
   */
public void testPlaySinglePeriodTimeline() throws Exception {
    PlayerWrapper playerWrapper = new PlayerWrapper();
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(false, false, 0));
    Object manifest = new Object();
    MediaSource mediaSource = new FakeMediaSource(timeline, manifest, TEST_VIDEO_FORMAT);
    FakeRenderer renderer = new FakeRenderer(TEST_VIDEO_FORMAT);
    playerWrapper.setup(mediaSource, renderer);
    playerWrapper.blockUntilEnded(TIMEOUT_MS);
    assertEquals(0, playerWrapper.positionDiscontinuityCount);
    assertEquals(1, renderer.formatReadCount);
    assertEquals(1, renderer.bufferReadCount);
    assertTrue(renderer.isEnded);
    assertEquals(timeline, playerWrapper.timeline);
    assertEquals(manifest, playerWrapper.manifest);
    assertEquals(new TrackGroupArray(new TrackGroup(TEST_VIDEO_FORMAT)), playerWrapper.trackGroups);
}
Also used : MediaSource(com.google.android.exoplayer2.source.MediaSource) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray)

Example 2 with FakeTimeline

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

the class ExoPlayerTest method testReadAheadToEndDoesNotResetRenderer.

/**
   * Tests that the player does not unnecessarily reset renderers when playing a multi-period
   * source.
   */
public void testReadAheadToEndDoesNotResetRenderer() throws Exception {
    final PlayerWrapper playerWrapper = new PlayerWrapper();
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(false, false, 10), new TimelineWindowDefinition(false, false, 10), new TimelineWindowDefinition(false, false, 10));
    MediaSource mediaSource = new FakeMediaSource(timeline, null, TEST_VIDEO_FORMAT, TEST_AUDIO_FORMAT);
    FakeRenderer videoRenderer = new FakeRenderer(TEST_VIDEO_FORMAT);
    FakeMediaClockRenderer audioRenderer = new FakeMediaClockRenderer(TEST_AUDIO_FORMAT) {

        @Override
        public long getPositionUs() {
            // TODO: Avoid hard-coding ExoPlayerImplInternal.RENDERER_TIMESTAMP_OFFSET_US.
            return isCurrentStreamFinal() ? 60000030 : 60000000;
        }

        @Override
        public boolean isEnded() {
            // Allow playback to end once the final period is playing.
            return playerWrapper.positionDiscontinuityCount == 2;
        }
    };
    playerWrapper.setup(mediaSource, videoRenderer, audioRenderer);
    playerWrapper.blockUntilEnded(TIMEOUT_MS);
    assertEquals(2, playerWrapper.positionDiscontinuityCount);
    assertEquals(1, audioRenderer.positionResetCount);
    assertTrue(videoRenderer.isEnded);
    assertTrue(audioRenderer.isEnded);
    assertEquals(timeline, playerWrapper.timeline);
    assertNull(playerWrapper.manifest);
}
Also used : MediaSource(com.google.android.exoplayer2.source.MediaSource)

Example 3 with FakeTimeline

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

the class TimelineTest method roundTripViaBundle_ofTimeline_preservesWindowIndices.

@Test
public void roundTripViaBundle_ofTimeline_preservesWindowIndices() {
    int windowCount = 10;
    FakeTimeline timeline = new FakeTimeline(windowCount);
    Timeline restoredTimeline = Timeline.CREATOR.fromBundle(timeline.toBundle());
    assertThat(restoredTimeline.getLastWindowIndex(/* shuffleModeEnabled= */
    false)).isEqualTo(timeline.getLastWindowIndex(/* shuffleModeEnabled= */
    false));
    assertThat(restoredTimeline.getLastWindowIndex(/* shuffleModeEnabled= */
    true)).isEqualTo(timeline.getLastWindowIndex(/* shuffleModeEnabled= */
    true));
    assertThat(restoredTimeline.getFirstWindowIndex(/* shuffleModeEnabled= */
    false)).isEqualTo(timeline.getFirstWindowIndex(/* shuffleModeEnabled= */
    false));
    assertThat(restoredTimeline.getFirstWindowIndex(/* shuffleModeEnabled= */
    true)).isEqualTo(timeline.getFirstWindowIndex(/* shuffleModeEnabled= */
    true));
    TimelineAsserts.assertEqualNextWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
    false);
    TimelineAsserts.assertEqualNextWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
    true);
    TimelineAsserts.assertEqualNextWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
    false);
    TimelineAsserts.assertEqualNextWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
    true);
    TimelineAsserts.assertEqualNextWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
    false);
    TimelineAsserts.assertEqualNextWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
    true);
    TimelineAsserts.assertEqualPreviousWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
    false);
    TimelineAsserts.assertEqualPreviousWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
    true);
    TimelineAsserts.assertEqualPreviousWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
    false);
    TimelineAsserts.assertEqualPreviousWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */
    true);
    TimelineAsserts.assertEqualPreviousWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
    false);
    TimelineAsserts.assertEqualPreviousWindowIndices(timeline, restoredTimeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */
    true);
}
Also used : FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Test(org.junit.Test)

Example 4 with FakeTimeline

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

the class TimelineTest method roundTripViaBundle_ofTimeline_yieldsEqualInstanceExceptIdsAndManifest.

@Test
public void roundTripViaBundle_ofTimeline_yieldsEqualInstanceExceptIdsAndManifest() {
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    2, /* id= */
    new Object(), /* isSeekable= */
    true, /* isDynamic= */
    true, /* isLive= */
    true, /* isPlaceholder= */
    false, /* durationUs= */
    2, /* defaultPositionUs= */
    22, /* windowOffsetInFirstPeriodUs= */
    222, ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setMediaId("mediaId2").build()), new TimelineWindowDefinition(/* periodCount= */
    3, /* id= */
    new Object(), /* isSeekable= */
    true, /* isDynamic= */
    true, /* isLive= */
    true, /* isPlaceholder= */
    false, /* durationUs= */
    3, /* defaultPositionUs= */
    33, /* windowOffsetInFirstPeriodUs= */
    333, ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setMediaId("mediaId3").build()));
    Timeline restoredTimeline = Timeline.CREATOR.fromBundle(timeline.toBundle());
    TimelineAsserts.assertEqualsExceptIdsAndManifest(/* expectedTimeline= */
    timeline, /* actualTimeline= */
    restoredTimeline);
}
Also used : FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) Test(org.junit.Test)

Example 5 with FakeTimeline

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

the class TimelineTest method singlePeriodTimeline.

@Test
public void singlePeriodTimeline() {
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(1, 111));
    TimelineAsserts.assertWindowTags(timeline, 111);
    TimelineAsserts.assertPeriodCounts(timeline, 1);
    TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, C.INDEX_UNSET);
    TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0);
    TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 0);
    TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, C.INDEX_UNSET);
    TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0);
    TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 0);
}
Also used : FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) Test(org.junit.Test)

Aggregations

FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)242 Test (org.junit.Test)240 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)159 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)136 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)118 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)117 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)117 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)98 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)87 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)69 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)62 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)62 MediaSource (com.google.android.exoplayer2.source.MediaSource)60 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)60 Timeline (com.google.android.exoplayer2.Timeline)53 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)50 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)49 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)49 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)49 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)49