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