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