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));
}
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;
}
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);
}
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);
}
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();
}
}
Aggregations