use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method moveMediaItems_correctMaskingMediaItemIndex.
@Test
public void moveMediaItems_correctMaskingMediaItemIndex() throws Exception {
Timeline timeline = new FakeTimeline();
MediaSource firstMediaSource = new FakeMediaSource(timeline);
MediaSource secondMediaSource = new FakeMediaSource(timeline);
MediaSource thirdMediaSource = new FakeMediaSource(timeline);
final int[] currentMediaItemIndices = { C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET };
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Move the current item down in the playlist.
player.moveMediaItems(/* fromIndex= */
0, /* toIndex= */
2, /* newIndex= */
1);
currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
}
}).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Move the current item up in the playlist.
player.moveMediaItems(/* fromIndex= */
1, /* toIndex= */
3, /* newIndex= */
0);
currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
}
}).seek(/* mediaItemIndex= */
2, C.TIME_UNSET).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Move items from before to behind the current item.
player.moveMediaItems(/* fromIndex= */
0, /* toIndex= */
2, /* newIndex= */
1);
currentMediaItemIndices[2] = player.getCurrentMediaItemIndex();
}
}).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Move items from behind to before the current item.
player.moveMediaItems(/* fromIndex= */
1, /* toIndex= */
3, /* newIndex= */
0);
currentMediaItemIndices[3] = player.getCurrentMediaItemIndex();
}
}).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Move items from before to before the current item.
// No change in currentMediaItemIndex.
player.moveMediaItems(/* fromIndex= */
0, /* toIndex= */
1, /* newIndex= */
1);
currentMediaItemIndices[4] = player.getCurrentMediaItemIndex();
}
}).seek(/* mediaItemIndex= */
0, C.TIME_UNSET).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Move items from behind to behind the current item.
// No change in currentMediaItemIndex.
player.moveMediaItems(/* fromIndex= */
1, /* toIndex= */
2, /* newIndex= */
2);
currentMediaItemIndices[5] = player.getCurrentMediaItemIndex();
}
}).build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(firstMediaSource, secondMediaSource, thirdMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertArrayEquals(new int[] { 1, 0, 0, 2, 2, 0 }, currentMediaItemIndices);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method sendMessagesMoveCurrentMediaItemIndex.
@Test
public void sendMessagesMoveCurrentMediaItemIndex() throws Exception {
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0));
final Timeline secondTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0));
final FakeMediaSource mediaSource = new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT);
PositionGrabbingMessageTarget target = new PositionGrabbingMessageTarget();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForTimelineChanged(timeline, /* expectedReason */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).sendMessage(target, /* positionMs= */
50).executeRunnable(() -> mediaSource.setNewSourceInfo(secondTimeline)).waitForTimelineChanged(secondTimeline, /* expectedReason */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).play().build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(target.positionMs).isAtLeast(50L);
assertThat(target.mediaItemIndex).isEqualTo(1);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method setPlaybackSpeedConsecutivelyNotifiesListenerForEveryChangeOnceAndIsMasked.
@Test
public void setPlaybackSpeedConsecutivelyNotifiesListenerForEveryChangeOnceAndIsMasked() throws Exception {
List<Float> maskedPlaybackSpeeds = new ArrayList<>();
Action getPlaybackSpeedAction = new Action("getPlaybackSpeed", /* description= */
null) {
@Override
protected void doActionImpl(ExoPlayer player, DefaultTrackSelector trackSelector, @Nullable Surface surface) {
maskedPlaybackSpeeds.add(player.getPlaybackParameters().speed);
}
};
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).setPlaybackParameters(new PlaybackParameters(/* speed= */
1.1f)).apply(getPlaybackSpeedAction).setPlaybackParameters(new PlaybackParameters(/* speed= */
1.2f)).apply(getPlaybackSpeedAction).setPlaybackParameters(new PlaybackParameters(/* speed= */
1.3f)).apply(getPlaybackSpeedAction).play().build();
List<Float> reportedPlaybackSpeeds = new ArrayList<>();
Player.Listener listener = new Player.Listener() {
@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
reportedPlaybackSpeeds.add(playbackParameters.speed);
}
};
new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).setPlayerListener(listener).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(reportedPlaybackSpeeds).containsExactly(1.1f, 1.2f, 1.3f).inOrder();
assertThat(maskedPlaybackSpeeds).isEqualTo(reportedPlaybackSpeeds);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method removeMediaItems_correctMaskingMediaItemIndex.
@Test
public void removeMediaItems_correctMaskingMediaItemIndex() throws Exception {
final int[] currentMediaItemIndices = { C.INDEX_UNSET, C.INDEX_UNSET };
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Decrease current media item index.
currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
player.removeMediaItem(/* index= */
0);
currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
}
}).build();
new ExoPlayerTestRunner.Builder(context).initialSeek(/* mediaItemIndex= */
1, /* positionMs= */
C.TIME_UNSET).setMediaSources(new FakeMediaSource(), new FakeMediaSource()).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertArrayEquals(new int[] { 1, 0 }, currentMediaItemIndices);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method sendMessagesAtStartAndEndOfPeriod.
@Test
public void sendMessagesAtStartAndEndOfPeriod() throws Exception {
Timeline timeline = new FakeTimeline(/* windowCount= */
2);
PositionGrabbingMessageTarget targetStartFirstPeriod = new PositionGrabbingMessageTarget();
PositionGrabbingMessageTarget targetEndMiddlePeriodResolved = new PositionGrabbingMessageTarget();
PositionGrabbingMessageTarget targetEndMiddlePeriodUnresolved = new PositionGrabbingMessageTarget();
PositionGrabbingMessageTarget targetStartMiddlePeriod = new PositionGrabbingMessageTarget();
PositionGrabbingMessageTarget targetEndLastPeriodResolved = new PositionGrabbingMessageTarget();
PositionGrabbingMessageTarget targetEndLastPeriodUnresolved = new PositionGrabbingMessageTarget();
long duration1Ms = timeline.getWindow(0, new Window()).getDurationMs();
long duration2Ms = timeline.getWindow(1, new Window()).getDurationMs();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).sendMessage(targetStartFirstPeriod, /* mediaItemIndex= */
0, /* positionMs= */
0).sendMessage(targetEndMiddlePeriodResolved, /* mediaItemIndex= */
0, /* positionMs= */
duration1Ms - 1).sendMessage(targetEndMiddlePeriodUnresolved, /* mediaItemIndex= */
0, /* positionMs= */
C.TIME_END_OF_SOURCE).sendMessage(targetStartMiddlePeriod, /* mediaItemIndex= */
1, /* positionMs= */
0).sendMessage(targetEndLastPeriodResolved, /* mediaItemIndex= */
1, /* positionMs= */
duration2Ms - 1).sendMessage(targetEndLastPeriodUnresolved, /* mediaItemIndex= */
1, /* positionMs= */
C.TIME_END_OF_SOURCE).waitForMessage(targetEndLastPeriodUnresolved).build();
new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertThat(targetStartFirstPeriod.mediaItemIndex).isEqualTo(0);
assertThat(targetStartFirstPeriod.positionMs).isAtLeast(0L);
assertThat(targetEndMiddlePeriodResolved.mediaItemIndex).isEqualTo(0);
assertThat(targetEndMiddlePeriodResolved.positionMs).isAtLeast(duration1Ms - 1);
assertThat(targetEndMiddlePeriodUnresolved.mediaItemIndex).isEqualTo(0);
assertThat(targetEndMiddlePeriodUnresolved.positionMs).isAtLeast(duration1Ms - 1);
assertThat(targetEndMiddlePeriodResolved.positionMs).isEqualTo(targetEndMiddlePeriodUnresolved.positionMs);
assertThat(targetStartMiddlePeriod.mediaItemIndex).isEqualTo(1);
assertThat(targetStartMiddlePeriod.positionMs).isAtLeast(0L);
assertThat(targetEndLastPeriodResolved.mediaItemIndex).isEqualTo(1);
assertThat(targetEndLastPeriodResolved.positionMs).isAtLeast(duration2Ms - 1);
assertThat(targetEndLastPeriodUnresolved.mediaItemIndex).isEqualTo(1);
assertThat(targetEndLastPeriodUnresolved.positionMs).isAtLeast(duration2Ms - 1);
assertThat(targetEndLastPeriodResolved.positionMs).isEqualTo(targetEndLastPeriodUnresolved.positionMs);
}
Aggregations