Search in sources :

Example 11 with PlaybackParameters

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

the class CastPlayerTest method setPlaybackParameters_speedOutOfRange_valueIsConstraintToMinAndMax.

@Test
public void setPlaybackParameters_speedOutOfRange_valueIsConstraintToMinAndMax() {
    when(mockRemoteMediaClient.setPlaybackRate(eq(2d), any())).thenReturn(mockPendingResult);
    when(mockRemoteMediaClient.setPlaybackRate(eq(0.5d), any())).thenReturn(mockPendingResult);
    PlaybackParameters expectedMaxValuePlaybackParameters = new PlaybackParameters(/* speed= */
    2f);
    PlaybackParameters expectedMinValuePlaybackParameters = new PlaybackParameters(/* speed= */
    0.5f);
    castPlayer.setPlaybackParameters(new PlaybackParameters(/* speed= */
    2.001f));
    verify(mockListener).onPlaybackParametersChanged(expectedMaxValuePlaybackParameters);
    castPlayer.setPlaybackParameters(new PlaybackParameters(/* speed= */
    0.499f));
    verify(mockListener).onPlaybackParametersChanged(expectedMinValuePlaybackParameters);
}
Also used : PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) Test(org.junit.Test)

Example 12 with PlaybackParameters

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

the class DefaultMediaClock method syncClocks.

private void syncClocks(boolean isReadingAhead) {
    if (shouldUseStandaloneClock(isReadingAhead)) {
        isUsingStandaloneClock = true;
        if (standaloneClockIsStarted) {
            standaloneClock.start();
        }
        return;
    }
    // We are either already using the renderer clock or switching from the standalone to the
    // renderer clock, so it must be non-null.
    MediaClock rendererClock = Assertions.checkNotNull(this.rendererClock);
    long rendererClockPositionUs = rendererClock.getPositionUs();
    if (isUsingStandaloneClock) {
        // Ensure enabling the renderer clock doesn't jump backwards in time.
        if (rendererClockPositionUs < standaloneClock.getPositionUs()) {
            standaloneClock.stop();
            return;
        }
        isUsingStandaloneClock = false;
        if (standaloneClockIsStarted) {
            standaloneClock.start();
        }
    }
    // Continuously sync stand-alone clock to renderer clock so that it can take over if needed.
    standaloneClock.resetPosition(rendererClockPositionUs);
    PlaybackParameters playbackParameters = rendererClock.getPlaybackParameters();
    if (!playbackParameters.equals(standaloneClock.getPlaybackParameters())) {
        standaloneClock.setPlaybackParameters(playbackParameters);
        listener.onPlaybackParametersChanged(playbackParameters);
    }
}
Also used : MediaClock(com.google.android.exoplayer2.util.MediaClock) StandaloneMediaClock(com.google.android.exoplayer2.util.StandaloneMediaClock)

Example 13 with PlaybackParameters

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

the class ExoPlayerTest method playerIdle_withSetPlaybackSpeed_usesPlaybackParameterSpeedWithPitchUnchanged.

@Test
public void playerIdle_withSetPlaybackSpeed_usesPlaybackParameterSpeedWithPitchUnchanged() {
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.setPlaybackParameters(new PlaybackParameters(/* speed= */
    1, /* pitch= */
    2));
    Player.Listener mockListener = mock(Player.Listener.class);
    player.addListener(mockListener);
    player.prepare();
    player.setPlaybackSpeed(2);
    verify(mockListener).onPlaybackParametersChanged(new PlaybackParameters(/* speed= */
    2, /* pitch= */
    2));
}
Also used : Listener(com.google.android.exoplayer2.Player.Listener) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 14 with PlaybackParameters

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

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

the class DefaultAudioSinkTest method setPlaybackParameters_doesNothingWhenTunnelingIsEnabled.

@Test
public void setPlaybackParameters_doesNothingWhenTunnelingIsEnabled() throws Exception {
    defaultAudioSink.setAudioSessionId(1);
    defaultAudioSink.enableTunnelingV21();
    defaultAudioSink.setPlaybackParameters(new PlaybackParameters(2));
    configureDefaultAudioSink(/* channelCount= */
    2);
    defaultAudioSink.handleBuffer(createDefaultSilenceBuffer(), /* presentationTimeUs= */
    5 * C.MICROS_PER_SECOND, /* encodedAccessUnitCount= */
    1);
    assertThat(defaultAudioSink.getPlaybackParameters().speed).isEqualTo(1);
}
Also used : PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) Test(org.junit.Test)

Aggregations

PlaybackParameters (com.google.android.exoplayer2.PlaybackParameters)20 Test (org.junit.Test)17 Listener (com.google.android.exoplayer2.Player.Listener)7 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)7 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)7 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)7 MediaSource (com.google.android.exoplayer2.source.MediaSource)4 ArrayList (java.util.ArrayList)4 Nullable (androidx.annotation.Nullable)3 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)3 ExtractorMediaSource (com.google.android.exoplayer2.source.ExtractorMediaSource)3 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)3 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)3 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)3 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)3 FakeMediaClockRenderer (com.google.android.exoplayer2.testutil.FakeMediaClockRenderer)3 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)3 Surface (android.view.Surface)2 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)2 SimpleExoPlayer (com.google.android.exoplayer2.SimpleExoPlayer)2