use of com.google.android.exoplayer2.testutil.FakeMediaSource in project ExoPlayer by google.
the class ExoPlayerTest method removeMediaItem.
@Test
public void removeMediaItem() throws Exception {
TimelineWindowDefinition firstWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(10000));
TimelineWindowDefinition secondWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
2, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(10000));
TimelineWindowDefinition thirdWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
3, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(10000));
Timeline timeline1 = new FakeTimeline(firstWindowDefinition);
Timeline timeline2 = new FakeTimeline(secondWindowDefinition);
Timeline timeline3 = new FakeTimeline(thirdWindowDefinition);
MediaSource mediaSource1 = new FakeMediaSource(timeline1);
MediaSource mediaSource2 = new FakeMediaSource(timeline2);
MediaSource mediaSource3 = new FakeMediaSource(timeline3);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).removeMediaItem(/* index= */
0).build();
ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource1, mediaSource2, mediaSource3).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
Timeline expectedPlaceholderTimeline = new FakeTimeline(TimelineWindowDefinition.createPlaceholder(/* tag= */
1), TimelineWindowDefinition.createPlaceholder(/* tag= */
2), TimelineWindowDefinition.createPlaceholder(/* tag= */
3));
Timeline expectedRealTimeline = new FakeTimeline(firstWindowDefinition, secondWindowDefinition, thirdWindowDefinition);
Timeline expectedRealTimelineAfterRemove = new FakeTimeline(secondWindowDefinition, thirdWindowDefinition);
exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
exoPlayerTestRunner.assertTimelinesSame(expectedPlaceholderTimeline, expectedRealTimeline, expectedRealTimelineAfterRemove);
}
use of com.google.android.exoplayer2.testutil.FakeMediaSource in project ExoPlayer by google.
the class ExoPlayerTest method release_triggersAllPendingEventsInAnalyticsListeners.
@Test
public void release_triggersAllPendingEventsInAnalyticsListeners() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(ApplicationProvider.getApplicationContext()).setRenderersFactory((handler, videoListener, audioListener, textOutput, metadataOutput) -> new Renderer[] { new FakeVideoRenderer(handler, videoListener) }).build();
AnalyticsListener listener = mock(AnalyticsListener.class);
player.addAnalyticsListener(listener);
// Do something that requires clean-up callbacks like decoder disabling.
player.setMediaSource(new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT));
player.prepare();
player.play();
runUntilPlaybackState(player, Player.STATE_READY);
player.release();
ShadowLooper.runMainLooperToNextTask();
verify(listener).onVideoDisabled(any(), any());
verify(listener).onPlayerReleased(any());
}
use of com.google.android.exoplayer2.testutil.FakeMediaSource in project ExoPlayer by google.
the class ExoPlayerTest method setRepeatMode_all_notifiesAvailableCommandsChanged.
@Test
public void setRepeatMode_all_notifiesAvailableCommandsChanged() {
Player.Commands defaultCommands = createWithDefaultCommands();
Player.Commands commandsWithSeekToPreviousAndNextWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT);
Player.Listener mockListener = mock(Player.Listener.class);
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.addListener(mockListener);
player.addMediaSource(new FakeMediaSource());
verify(mockListener).onAvailableCommandsChanged(defaultCommands);
// Check that there were no other calls to onAvailableCommandsChanged.
verify(mockListener).onAvailableCommandsChanged(any());
player.setRepeatMode(Player.REPEAT_MODE_ALL);
verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousAndNextWindow);
verify(mockListener, times(2)).onAvailableCommandsChanged(any());
}
use of com.google.android.exoplayer2.testutil.FakeMediaSource in project ExoPlayer by google.
the class ExoPlayerTest method playShortDurationPeriods.
/**
* Tests playback of periods with very short duration.
*/
@Test
public void playShortDurationPeriods() throws Exception {
// TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US / 100 = 1000 us per period.
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
100, /* id= */
0));
FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
Player.Listener mockPlayerListener = mock(Player.Listener.class);
player.addListener(mockPlayerListener);
player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
player.prepare();
player.play();
runUntilPlaybackState(player, Player.STATE_ENDED);
InOrder inOrder = inOrder(mockPlayerListener);
inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(placeholderTimeline)), 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(99)).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
assertThat(renderer.getFormatsRead()).hasSize(100);
assertThat(renderer.sampleBufferReadCount).isEqualTo(100);
assertThat(renderer.isEnded).isTrue();
}
use of com.google.android.exoplayer2.testutil.FakeMediaSource in project ExoPlayer by google.
the class ExoPlayerTest method allActivatedTrackSelectionAreReleasedWhenTrackSelectionsAreReused.
@Test
public void allActivatedTrackSelectionAreReleasedWhenTrackSelectionsAreReused() 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);
final FakeTrackSelector trackSelector = new FakeTrackSelector(/* mayReuseTrackSelection= */
true);
ActionSchedule disableTrackAction = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).disableRenderer(0).play().build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setRenderers(videoRenderer, audioRenderer).setTrackSelector(trackSelector).setActionSchedule(disableTrackAction).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. The second time one renderer is
// disabled, and the selector re-uses the previous selection for the enabled renderer. So we
// expect two track selections, one of which will have been enabled twice.
assertThat(createdTrackSelections).hasSize(2);
assertThat(numSelectionsEnabled).isEqualTo(3);
}
Aggregations