use of com.google.android.exoplayer2.testutil.FakeRenderer in project ExoPlayer by google.
the class ExoPlayerTest method testPlayEmptyTimeline.
/**
* Tests playback of a source that exposes an empty timeline. Playback is expected to end without
* error.
*/
public void testPlayEmptyTimeline() throws Exception {
PlayerWrapper playerWrapper = new PlayerWrapper();
Timeline timeline = Timeline.EMPTY;
MediaSource mediaSource = new FakeMediaSource(timeline, null);
FakeRenderer renderer = new FakeRenderer(null);
playerWrapper.setup(mediaSource, renderer);
playerWrapper.blockUntilEnded(TIMEOUT_MS);
assertEquals(0, playerWrapper.positionDiscontinuityCount);
assertEquals(0, renderer.formatReadCount);
assertEquals(0, renderer.bufferReadCount);
assertFalse(renderer.isEnded);
assertEquals(timeline, playerWrapper.timeline);
assertNull(playerWrapper.manifest);
}
use of com.google.android.exoplayer2.testutil.FakeRenderer in project ExoPlayer by google.
the class ExoPlayerTest method allActivatedTrackSelectionAreReleasedForMultiPeriods.
@Test
public void allActivatedTrackSelectionAreReleasedForMultiPeriods() throws Exception {
Timeline timeline = new FakeTimeline(/* windowCount= */
2);
MediaSource mediaSource = new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.AUDIO_FORMAT);
FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO);
FakeTrackSelector trackSelector = new FakeTrackSelector();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setRenderers(videoRenderer, audioRenderer).setTrackSelector(trackSelector).build().start().blockUntilEnded(TIMEOUT_MS);
List<FakeTrackSelection> createdTrackSelections = trackSelector.getAllTrackSelections();
int numSelectionsEnabled = 0;
// Assert that all tracks selection are disabled at the end of the playback.
for (FakeTrackSelection trackSelection : createdTrackSelections) {
assertThat(trackSelection.isEnabled).isFalse();
numSelectionsEnabled += trackSelection.enableCount;
}
// There are 2 renderers, and track selections are made twice (2 periods).
assertThat(createdTrackSelections).hasSize(4);
assertThat(numSelectionsEnabled).isEqualTo(4);
}
use of com.google.android.exoplayer2.testutil.FakeRenderer in project ExoPlayer by google.
the class ExoPlayerTest method renderersLifecycle_setForegroundMode_resetsDisabledRenderersThatHaveBeenEnabled.
@Test
public void renderersLifecycle_setForegroundMode_resetsDisabledRenderersThatHaveBeenEnabled() throws Exception {
Timeline timeline = new FakeTimeline();
final FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
final FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO);
final FakeRenderer textRenderer = new FakeRenderer(C.TRACK_TYPE_TEXT);
ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(videoRenderer, audioRenderer).build();
Player.Listener mockPlayerListener = mock(Player.Listener.class);
player.addListener(mockPlayerListener);
player.setMediaSources(ImmutableList.of(new FakeMediaSource(timeline, ExoPlayerTestRunner.AUDIO_FORMAT, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(timeline, ExoPlayerTestRunner.AUDIO_FORMAT)));
player.prepare();
player.play();
runUntilPositionDiscontinuity(player, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
player.setForegroundMode(/* foregroundMode= */
true);
// Only the video renderer that is disabled in the second media item has been reset.
assertThat(audioRenderer.resetCount).isEqualTo(0);
assertThat(videoRenderer.resetCount).isEqualTo(1);
runUntilPlaybackState(player, Player.STATE_ENDED);
player.release();
// After release the audio renderer is reset as well.
assertThat(audioRenderer.enabledCount).isEqualTo(1);
assertThat(audioRenderer.resetCount).isEqualTo(1);
assertThat(videoRenderer.enabledCount).isEqualTo(1);
assertThat(videoRenderer.resetCount).isEqualTo(1);
assertThat(textRenderer.enabledCount).isEqualTo(0);
assertThat(textRenderer.resetCount).isEqualTo(0);
}
use of com.google.android.exoplayer2.testutil.FakeRenderer in project ExoPlayer by google.
the class ExoPlayerTest method allActivatedTrackSelectionAreReleasedForSinglePeriod.
@Test
public void allActivatedTrackSelectionAreReleasedForSinglePeriod() throws Exception {
MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.AUDIO_FORMAT);
FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO);
FakeTrackSelector trackSelector = new FakeTrackSelector();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setRenderers(videoRenderer, audioRenderer).setTrackSelector(trackSelector).build().start().blockUntilEnded(TIMEOUT_MS);
List<FakeTrackSelection> createdTrackSelections = trackSelector.getAllTrackSelections();
int numSelectionsEnabled = 0;
// Assert that all tracks selection are disabled at the end of the playback.
for (FakeTrackSelection trackSelection : createdTrackSelections) {
assertThat(trackSelection.isEnabled).isFalse();
numSelectionsEnabled += trackSelection.enableCount;
}
// There are 2 renderers, and track selections are made once (1 period).
assertThat(createdTrackSelections).hasSize(2);
assertThat(numSelectionsEnabled).isEqualTo(2);
}
use of com.google.android.exoplayer2.testutil.FakeRenderer in project ExoPlayer by google.
the class ExoPlayerTest method setAndSwitchSurface.
@Test
public void setAndSwitchSurface() throws Exception {
final List<Integer> rendererMessages = new ArrayList<>();
Renderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO) {
@Override
public void handleMessage(@MessageType int messageType, @Nullable Object message) throws ExoPlaybackException {
super.handleMessage(messageType, message);
rendererMessages.add(messageType);
}
};
ActionSchedule actionSchedule = addSurfaceSwitch(new ActionSchedule.Builder(TAG)).build();
new ExoPlayerTestRunner.Builder(context).setRenderers(videoRenderer).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertThat(Collections.frequency(rendererMessages, Renderer.MSG_SET_VIDEO_OUTPUT)).isEqualTo(2);
}
Aggregations