use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method cancelMessageBeforeDelivery.
@Test
public void cancelMessageBeforeDelivery() throws Exception {
final PositionGrabbingMessageTarget target = new PositionGrabbingMessageTarget();
final AtomicReference<PlayerMessage> message = new AtomicReference<>();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
message.set(player.createMessage(target).setPosition(/* positionMs= */
50).send());
}
}).playUntilPosition(/* mediaItemIndex= */
0, /* positionMs= */
30).executeRunnable(() -> message.get().cancel()).play().build();
new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(message.get().isCanceled()).isTrue();
assertThat(target.messageCount).isEqualTo(0);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method moveMediaItem_behindLoadingPeriod_correctMaskingPosition.
@Test
public void moveMediaItem_behindLoadingPeriod_correctMaskingPosition() throws Exception {
final int[] mediaItemIndex = { C.INDEX_UNSET, C.INDEX_UNSET };
final long[] positionMs = { C.INDEX_UNSET, C.INDEX_UNSET };
final long[] bufferedPositions = { C.INDEX_UNSET, C.INDEX_UNSET };
final long[] totalBufferedDuration = { C.INDEX_UNSET, C.INDEX_UNSET };
runPositionMaskingCapturingActionSchedule(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
player.moveMediaItem(/* currentIndex= */
1, /* newIndex= */
2);
}
}, /* pauseMediaItemIndex= */
0, mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, new FakeMediaSource(), new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */
4000));
assertThat(mediaItemIndex[0]).isEqualTo(0);
assertThat(positionMs[0]).isAtLeast(8000);
assertThat(bufferedPositions[0]).isEqualTo(10_000);
assertThat(totalBufferedDuration[0]).isEqualTo(10_000 - positionMs[0]);
assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]);
assertThat(positionMs[1]).isEqualTo(positionMs[0]);
assertThat(bufferedPositions[1]).isEqualTo(10_000);
assertThat(totalBufferedDuration[1]).isEqualTo(10_000 - positionMs[1]);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method clearMediaItems_correctMaskingPosition.
@Test
public void clearMediaItems_correctMaskingPosition() throws Exception {
final int[] mediaItemIndex = { C.INDEX_UNSET, C.INDEX_UNSET };
final long[] positionMs = { C.INDEX_UNSET, C.INDEX_UNSET };
final long[] bufferedPositions = { C.INDEX_UNSET, C.INDEX_UNSET };
final long[] totalBufferedDuration = { C.INDEX_UNSET, C.INDEX_UNSET };
runPositionMaskingCapturingActionSchedule(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
player.clearMediaItems();
}
}, /* pauseMediaItemIndex= */
0, mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, new FakeMediaSource(), new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */
4000));
assertThat(mediaItemIndex[0]).isEqualTo(0);
assertThat(positionMs[0]).isEqualTo(0);
assertThat(bufferedPositions[0]).isEqualTo(0);
assertThat(totalBufferedDuration[0]).isEqualTo(0);
assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]);
assertThat(positionMs[1]).isEqualTo(positionMs[0]);
assertThat(bufferedPositions[1]).isEqualTo(bufferedPositions[0]);
assertThat(totalBufferedDuration[1]).isEqualTo(totalBufferedDuration[0]);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method multipleListenersAndMultipleCallbacks_callbacksAreOrderedByType.
@Test
public void multipleListenersAndMultipleCallbacks_callbacksAreOrderedByType() throws Exception {
String playWhenReadyChange1 = "playWhenReadyChange1";
String playWhenReadyChange2 = "playWhenReadyChange2";
String isPlayingChange1 = "isPlayingChange1";
String isPlayingChange2 = "isPlayingChange2";
ArrayList<String> events = new ArrayList<>();
Player.Listener playerListener1 = new Player.Listener() {
@Override
public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
events.add(playWhenReadyChange1);
}
@Override
public void onIsPlayingChanged(boolean isPlaying) {
events.add(isPlayingChange1);
}
};
Player.Listener playerListener2 = new Player.Listener() {
@Override
public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
events.add(playWhenReadyChange2);
}
@Override
public void onIsPlayingChanged(boolean isPlaying) {
events.add(isPlayingChange2);
}
};
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
player.addListener(playerListener1);
player.addListener(playerListener2);
}
}).waitForPlaybackState(Player.STATE_READY).play().waitForPlaybackState(Player.STATE_ENDED).build();
new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertThat(events).containsExactly(playWhenReadyChange1, playWhenReadyChange2, isPlayingChange1, isPlayingChange2, isPlayingChange1, isPlayingChange2).inOrder();
}
use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method seekToCurrentPosition_inEndedState_switchesToBufferingStateAndContinuesPlayback.
@Test
public void seekToCurrentPosition_inEndedState_switchesToBufferingStateAndContinuesPlayback() throws Exception {
MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(/* windowCount = */
1));
AtomicInteger mediaItemIndexAfterFinalEndedState = new AtomicInteger();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_ENDED).addMediaSources(mediaSource).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
player.seekTo(player.getCurrentPosition());
}
}).waitForPlaybackState(Player.STATE_READY).waitForPlaybackState(Player.STATE_ENDED).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
mediaItemIndexAfterFinalEndedState.set(player.getCurrentMediaItemIndex());
}
}).build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertThat(mediaItemIndexAfterFinalEndedState.get()).isEqualTo(1);
}
Aggregations