use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method stop_withoutReset_doesNotResetPosition_correctMasking.
@Test
public void stop_withoutReset_doesNotResetPosition_correctMasking() throws Exception {
int[] currentMediaItemIndex = { C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET };
long[] currentPosition = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
long[] bufferedPosition = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
long[] totalBufferedDuration = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
final FakeMediaSource mediaSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().seek(/* mediaItemIndex= */
1, /* positionMs= */
1000).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
currentMediaItemIndex[0] = player.getCurrentMediaItemIndex();
currentPosition[0] = player.getCurrentPosition();
bufferedPosition[0] = player.getBufferedPosition();
totalBufferedDuration[0] = player.getTotalBufferedDuration();
player.stop(/* reset= */
false);
currentMediaItemIndex[1] = player.getCurrentMediaItemIndex();
currentPosition[1] = player.getCurrentPosition();
bufferedPosition[1] = player.getBufferedPosition();
totalBufferedDuration[1] = player.getTotalBufferedDuration();
}
}).waitForPlaybackState(Player.STATE_IDLE).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
currentMediaItemIndex[2] = player.getCurrentMediaItemIndex();
currentPosition[2] = player.getCurrentPosition();
bufferedPosition[2] = player.getBufferedPosition();
totalBufferedDuration[2] = player.getTotalBufferedDuration();
}
}).build();
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource, mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
testRunner.assertPositionDiscontinuityReasonsEqual(Player.DISCONTINUITY_REASON_SEEK);
assertThat(currentMediaItemIndex[0]).isEqualTo(1);
assertThat(currentPosition[0]).isEqualTo(1000);
assertThat(bufferedPosition[0]).isEqualTo(10000);
assertThat(totalBufferedDuration[0]).isEqualTo(9000);
assertThat(currentMediaItemIndex[1]).isEqualTo(1);
assertThat(currentPosition[1]).isEqualTo(1000);
assertThat(bufferedPosition[1]).isEqualTo(1000);
assertThat(totalBufferedDuration[1]).isEqualTo(0);
assertThat(currentMediaItemIndex[2]).isEqualTo(1);
assertThat(currentPosition[2]).isEqualTo(1000);
assertThat(bufferedPosition[2]).isEqualTo(1000);
assertThat(totalBufferedDuration[2]).isEqualTo(0);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method switchSurfaceOnEndedState.
@Test
public void switchSurfaceOnEndedState() throws Exception {
ActionSchedule.Builder scheduleBuilder = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_ENDED);
ActionSchedule waitForEndedAndSwitchSchedule = addSurfaceSwitch(scheduleBuilder).build();
new ExoPlayerTestRunner.Builder(context).setTimeline(Timeline.EMPTY).setActionSchedule(waitForEndedAndSwitchSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method sendMessagesMultiWindowAfterPreparation.
@Test
public void sendMessagesMultiWindowAfterPreparation() throws Exception {
Timeline timeline = new FakeTimeline(/* windowCount= */
3);
PositionGrabbingMessageTarget target = new PositionGrabbingMessageTarget();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForTimelineChanged(timeline, /* expectedReason */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).sendMessage(target, /* mediaItemIndex = */
2, /* positionMs= */
50).play().build();
new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(target.mediaItemIndex).isEqualTo(2);
assertThat(target.positionMs).isAtLeast(50L);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method stopWithNoReset_modifyingPlaylistRemainsInIdleState_needsPrepareForBuffering.
@Test
public void stopWithNoReset_modifyingPlaylistRemainsInIdleState_needsPrepareForBuffering() throws Exception {
Timeline timeline = new FakeTimeline();
FakeMediaSource secondMediaSource = new FakeMediaSource(timeline);
int[] playbackStateHolder = new int[3];
int[] windowCountHolder = new int[3];
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).stop(/* reset= */
false).executeRunnable(new PlaybackStateCollector(/* index= */
0, playbackStateHolder, windowCountHolder)).clearMediaItems().executeRunnable(new PlaybackStateCollector(/* index= */
1, playbackStateHolder, windowCountHolder)).addMediaSources(secondMediaSource).executeRunnable(new PlaybackStateCollector(/* index= */
2, playbackStateHolder, windowCountHolder)).prepare().waitForPlaybackState(Player.STATE_BUFFERING).waitForPlaybackState(Player.STATE_READY).waitForPlaybackState(Player.STATE_ENDED).build();
ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertArrayEquals(new int[] { Player.STATE_IDLE, Player.STATE_IDLE, Player.STATE_IDLE }, playbackStateHolder);
assertArrayEquals(new int[] { 1, 0, 1 }, windowCountHolder);
exoPlayerTestRunner.assertPlaybackStatesEqual(// first buffering
Player.STATE_BUFFERING, Player.STATE_READY, // stop
Player.STATE_IDLE, Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED);
exoPlayerTestRunner.assertTimelinesSame(placeholderTimeline, timeline, Timeline.EMPTY, placeholderTimeline, timeline);
exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* media item set (masked timeline) */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, /* source prepared */
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* clear media items */
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* media item add (masked timeline) */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method sendMessagesMultiPeriodResolution.
@Test
public void sendMessagesMultiPeriodResolution() throws Exception {
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
10, /* id= */
0));
PositionGrabbingMessageTarget target = new PositionGrabbingMessageTarget();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).sendMessage(target, /* positionMs= */
50).play().build();
new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(target.positionMs).isAtLeast(50L);
}
Aggregations