Search in sources :

Example 6 with FakeMediaClockRenderer

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

the class ExoPlayerTest method readAheadToEndDoesNotResetRenderer.

/**
 * Tests that the player does not unnecessarily reset renderers when playing a multi-period
 * source.
 */
@Test
public void readAheadToEndDoesNotResetRenderer() throws Exception {
    // Use sufficiently short periods to ensure the player attempts to read all at once.
    TimelineWindowDefinition windowDefinition0 = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    false, /* isDynamic= */
    false, /* durationUs= */
    100_000);
    TimelineWindowDefinition windowDefinition1 = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    1, /* isSeekable= */
    false, /* isDynamic= */
    false, /* durationUs= */
    100_000);
    TimelineWindowDefinition windowDefinition2 = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    2, /* isSeekable= */
    false, /* isDynamic= */
    false, /* durationUs= */
    100_000);
    Timeline timeline = new FakeTimeline(windowDefinition0, windowDefinition1, windowDefinition2);
    final FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    FakeMediaClockRenderer audioRenderer = new FakeMediaClockRenderer(C.TRACK_TYPE_AUDIO) {

        @Override
        public long getPositionUs() {
            // to advance.
            return isCurrentStreamFinal() ? 30 : 0;
        }

        @Override
        public void setPlaybackParameters(PlaybackParameters playbackParameters) {
        }

        @Override
        public PlaybackParameters getPlaybackParameters() {
            return PlaybackParameters.DEFAULT;
        }

        @Override
        public boolean isEnded() {
            return videoRenderer.isEnded();
        }
    };
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(videoRenderer, audioRenderer).build();
    Player.Listener mockPlayerListener = mock(Player.Listener.class);
    player.addListener(mockPlayerListener);
    player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.AUDIO_FORMAT));
    player.prepare();
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    InOrder inOrder = inOrder(mockPlayerListener);
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(new FakeMediaSource.InitialTimeline(timeline))), 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(2)).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    assertThat(audioRenderer.positionResetCount).isEqualTo(1);
    assertThat(videoRenderer.isEnded).isTrue();
    assertThat(audioRenderer.isEnded).isTrue();
}
Also used : InOrder(org.mockito.InOrder) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) 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) 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)

Example 7 with FakeMediaClockRenderer

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

the class ExoPlayerTest method setUnsupportedPlaybackSpeedConsecutivelyNotifiesListenerForEveryChangeOnceAndResetsOnceHandled.

@Test
public void setUnsupportedPlaybackSpeedConsecutivelyNotifiesListenerForEveryChangeOnceAndResetsOnceHandled() throws Exception {
    Renderer renderer = new FakeMediaClockRenderer(C.TRACK_TYPE_AUDIO) {

        @Override
        public long getPositionUs() {
            return 0;
        }

        @Override
        public void setPlaybackParameters(PlaybackParameters playbackParameters) {
        }

        @Override
        public PlaybackParameters getPlaybackParameters() {
            return PlaybackParameters.DEFAULT;
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).setPlaybackParameters(new PlaybackParameters(/* speed= */
    1.1f)).setPlaybackParameters(new PlaybackParameters(/* speed= */
    1.2f)).setPlaybackParameters(new PlaybackParameters(/* speed= */
    1.3f)).play().build();
    List<PlaybackParameters> reportedPlaybackParameters = new ArrayList<>();
    Player.Listener listener = new Player.Listener() {

        @Override
        public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
            reportedPlaybackParameters.add(playbackParameters);
        }
    };
    new ExoPlayerTestRunner.Builder(context).setSupportedFormats(ExoPlayerTestRunner.AUDIO_FORMAT).setRenderers(renderer).setActionSchedule(actionSchedule).setPlayerListener(listener).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(reportedPlaybackParameters).containsExactly(new PlaybackParameters(/* speed= */
    1.1f), new PlaybackParameters(/* speed= */
    1.2f), new PlaybackParameters(/* speed= */
    1.3f), PlaybackParameters.DEFAULT).inOrder();
}
Also used : Listener(com.google.android.exoplayer2.Player.Listener) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Listener(com.google.android.exoplayer2.Player.Listener) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) FakeVideoRenderer(com.google.android.exoplayer2.testutil.FakeVideoRenderer) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) ArrayList(java.util.ArrayList) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) Test(org.junit.Test)

Example 8 with FakeMediaClockRenderer

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

the class DefaultMediaClockTest method rendererClockSetPlaybackSpeed_getPlaybackParametersShouldReturnSameValue.

@Test
public void rendererClockSetPlaybackSpeed_getPlaybackParametersShouldReturnSameValue() throws ExoPlaybackException {
    FakeMediaClockRenderer mediaClockRenderer = new MediaClockRenderer(PlaybackParameters.DEFAULT, /* playbackParametersAreMutable= */
    true);
    mediaClock.onRendererEnabled(mediaClockRenderer);
    mediaClock.syncAndGetPositionUs(/* isReadingAhead= */
    false);
    mediaClock.setPlaybackParameters(TEST_PLAYBACK_PARAMETERS);
    assertThat(mediaClock.getPlaybackParameters()).isEqualTo(TEST_PLAYBACK_PARAMETERS);
}
Also used : FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) Test(org.junit.Test)

Example 9 with FakeMediaClockRenderer

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

the class DefaultMediaClockTest method rendererClockSetPlaybackSpeedOverwrite_getPlaybackParametersShouldReturnSameValue.

@Test
public void rendererClockSetPlaybackSpeedOverwrite_getPlaybackParametersShouldReturnSameValue() throws ExoPlaybackException {
    FakeMediaClockRenderer mediaClockRenderer = new MediaClockRenderer(PlaybackParameters.DEFAULT, /* playbackParametersAreMutable= */
    false);
    mediaClock.onRendererEnabled(mediaClockRenderer);
    mediaClock.syncAndGetPositionUs(/* isReadingAhead= */
    false);
    mediaClock.setPlaybackParameters(TEST_PLAYBACK_PARAMETERS);
    assertThat(mediaClock.getPlaybackParameters()).isEqualTo(PlaybackParameters.DEFAULT);
}
Also used : FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) Test(org.junit.Test)

Example 10 with FakeMediaClockRenderer

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

the class DefaultMediaClockTest method enableRendererMediaClockWithFixedButSamePlaybackSpeed_shouldNotTriggerCallback.

@Test
public void enableRendererMediaClockWithFixedButSamePlaybackSpeed_shouldNotTriggerCallback() throws ExoPlaybackException {
    FakeMediaClockRenderer mediaClockRenderer = new MediaClockRenderer(PlaybackParameters.DEFAULT, /* playbackParametersAreMutable= */
    false);
    mediaClock.onRendererEnabled(mediaClockRenderer);
    mediaClock.syncAndGetPositionUs(/* isReadingAhead= */
    false);
    verifyNoMoreInteractions(listener);
}
Also used : FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) Test(org.junit.Test)

Aggregations

FakeMediaClockRenderer (com.google.android.exoplayer2.testutil.FakeMediaClockRenderer)11 Test (org.junit.Test)11 Listener (com.google.android.exoplayer2.Player.Listener)3 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)2 FakeRenderer (com.google.android.exoplayer2.testutil.FakeRenderer)2 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)2 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)2 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)2 ArrayList (java.util.ArrayList)2 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)1 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)1 MediaSource (com.google.android.exoplayer2.source.MediaSource)1 MediaSourceEventListener (com.google.android.exoplayer2.source.MediaSourceEventListener)1 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)1 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)1 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)1 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)1 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)1 FakeVideoRenderer (com.google.android.exoplayer2.testutil.FakeVideoRenderer)1 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)1