Search in sources :

Example 6 with PlaybackParameters

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

the class DefaultAnalyticsCollector method onPlaybackParametersChanged.

@Override
public final void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
    EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();
    sendEvent(eventTime, AnalyticsListener.EVENT_PLAYBACK_PARAMETERS_CHANGED, listener -> listener.onPlaybackParametersChanged(eventTime, playbackParameters));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 7 with PlaybackParameters

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

the class DefaultAudioSink method setAudioTrackPlaybackParametersV23.

@RequiresApi(23)
private void setAudioTrackPlaybackParametersV23(PlaybackParameters audioTrackPlaybackParameters) {
    if (isAudioTrackInitialized()) {
        PlaybackParams playbackParams = new PlaybackParams().allowDefaults().setSpeed(audioTrackPlaybackParameters.speed).setPitch(audioTrackPlaybackParameters.pitch).setAudioFallbackMode(PlaybackParams.AUDIO_FALLBACK_MODE_FAIL);
        try {
            audioTrack.setPlaybackParams(playbackParams);
        } catch (IllegalArgumentException e) {
            Log.w(TAG, "Failed to set playback params", e);
        }
        // Update the speed using the actual effective speed from the audio track.
        audioTrackPlaybackParameters = new PlaybackParameters(audioTrack.getPlaybackParams().getSpeed(), audioTrack.getPlaybackParams().getPitch());
        audioTrackPositionTracker.setAudioTrackPlaybackSpeed(audioTrackPlaybackParameters.speed);
    }
    this.audioTrackPlaybackParameters = audioTrackPlaybackParameters;
}
Also used : PlaybackParams(android.media.PlaybackParams) PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) RequiresApi(androidx.annotation.RequiresApi)

Example 8 with PlaybackParameters

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

the class CastPlayerTest method setPlaybackParameters_speedChangeNotSupported_resetOnResultCallback.

@Test
public void setPlaybackParameters_speedChangeNotSupported_resetOnResultCallback() {
    when(mockRemoteMediaClient.setPlaybackRate(eq((double) 1.234f), any())).thenReturn(mockPendingResult);
    PlaybackParameters playbackParameters = new PlaybackParameters(/* speed= */
    1.234f);
    // Change the playback speed and and capture the result callback.
    castPlayer.setPlaybackParameters(playbackParameters);
    verify(mockPendingResult).setResultCallback(setResultCallbackArgumentCaptor.capture());
    verify(mockListener).onPlaybackParametersChanged(new PlaybackParameters(/* speed= */
    1.234f));
    // The device does not support speed changes and returns unit speed to the result callback.
    when(mockMediaStatus.getPlaybackRate()).thenReturn(1.0d);
    setResultCallbackArgumentCaptor.getValue().onResult(mock(RemoteMediaClient.MediaChannelResult.class));
    assertThat(castPlayer.getPlaybackParameters()).isEqualTo(PlaybackParameters.DEFAULT);
    verify(mockListener).onPlaybackParametersChanged(PlaybackParameters.DEFAULT);
    verifyNoMoreInteractions(mockListener);
}
Also used : PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) Test(org.junit.Test)

Example 9 with PlaybackParameters

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

the class CastPlayerTest method setPlaybackParameters_masksPendingState.

@Test
public void setPlaybackParameters_masksPendingState() {
    PlaybackParameters playbackParameters = new PlaybackParameters(/* speed= */
    1.234f);
    when(mockRemoteMediaClient.setPlaybackRate(eq((double) 1.234f), any())).thenReturn(mockPendingResult);
    castPlayer.setPlaybackParameters(playbackParameters);
    verify(mockPendingResult).setResultCallback(setResultCallbackArgumentCaptor.capture());
    assertThat(castPlayer.getPlaybackParameters().speed).isEqualTo(1.234f);
    verify(mockListener).onPlaybackParametersChanged(playbackParameters);
    // Simulate a status update while the update is pending that must not override the masked speed.
    when(mockMediaStatus.getPlaybackRate()).thenReturn(99.0d);
    remoteMediaClientCallback.onStatusUpdated();
    assertThat(castPlayer.getPlaybackParameters().speed).isEqualTo(1.234f);
    // Call the captured result callback when the device responds. The listener must not be called.
    when(mockMediaStatus.getPlaybackRate()).thenReturn(1.234d);
    setResultCallbackArgumentCaptor.getValue().onResult(mock(RemoteMediaClient.MediaChannelResult.class));
    assertThat(castPlayer.getPlaybackParameters().speed).isEqualTo(1.234f);
    verifyNoMoreInteractions(mockListener);
}
Also used : PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) Test(org.junit.Test)

Example 10 with PlaybackParameters

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

the class CastPlayer method updatePlaybackRateAndNotifyIfChanged.

@RequiresNonNull("remoteMediaClient")
private void updatePlaybackRateAndNotifyIfChanged(@Nullable ResultCallback<?> resultCallback) {
    if (playbackParameters.acceptsUpdate(resultCallback)) {
        @Nullable MediaStatus mediaStatus = remoteMediaClient.getMediaStatus();
        float speed = mediaStatus != null ? (float) mediaStatus.getPlaybackRate() : PlaybackParameters.DEFAULT.speed;
        if (speed > 0.0f) {
            // Set the speed if not paused.
            setPlaybackParametersAndNotifyIfChanged(new PlaybackParameters(speed));
        }
        playbackParameters.clearPendingResultCallback();
    }
}
Also used : Nullable(androidx.annotation.Nullable) MediaStatus(com.google.android.gms.cast.MediaStatus) PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

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