Search in sources :

Example 1 with TimelineWindowDefinition

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition 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 TimelineWindowDefinition

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition 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 TimelineWindowDefinition

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition 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 4 with TimelineWindowDefinition

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

Example 5 with TimelineWindowDefinition

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

the class ExoPlayerTest method playShortDurationPeriods.

/**
 * Tests playback of periods with very short duration.
 */
@Test
public void playShortDurationPeriods() throws Exception {
    // TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US / 100 = 1000 us per period.
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    100, /* id= */
    0));
    FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
    Player.Listener mockPlayerListener = mock(Player.Listener.class);
    player.addListener(mockPlayerListener);
    player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
    player.prepare();
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    InOrder inOrder = inOrder(mockPlayerListener);
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(placeholderTimeline)), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(timeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
    inOrder.verify(mockPlayerListener, times(99)).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    assertThat(renderer.getFormatsRead()).hasSize(100);
    assertThat(renderer.sampleBufferReadCount).isEqualTo(100);
    assertThat(renderer.isEnded).isTrue();
}
Also used : FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) Listener(com.google.android.exoplayer2.Player.Listener) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) InOrder(org.mockito.InOrder) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)103 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)101 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)101 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)79 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)69 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)61 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)61 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)35 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)30 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)28 Listener (com.google.android.exoplayer2.Player.Listener)27 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)26 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)22 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)20 Timeline (com.google.android.exoplayer2.Timeline)19 MediaSource (com.google.android.exoplayer2.source.MediaSource)19 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)18 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)16 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)16 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)16