use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method seekTo_toLoadingPeriod_withinPartiallyBufferedData_correctMaskingPosition.
@Test
public void seekTo_toLoadingPeriod_withinPartiallyBufferedData_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.seekTo(1, 1000);
}
}, /* pauseMediaItemIndex= */
0, mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */
4000));
assertThat(mediaItemIndex[0]).isEqualTo(1);
assertThat(positionMs[0]).isEqualTo(1000);
// TODO(b/160450903): Verify masking of buffering properties when behaviour in EPII is fully
// covered.
// assertThat(bufferedPositions[0]).isEqualTo(1000);
// assertThat(totalBufferedDuration[0]).isEqualTo(0);
assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]);
assertThat(positionMs[1]).isEqualTo(positionMs[0]);
assertThat(bufferedPositions[1]).isEqualTo(4000);
assertThat(totalBufferedDuration[1]).isEqualTo(3000);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method removeMediaItems_currentItemRemoved_correctMasking.
@Test
public void removeMediaItems_currentItemRemoved_correctMasking() throws Exception {
final int[] currentMediaItemIndices = { C.INDEX_UNSET, C.INDEX_UNSET };
final long[] currentPositions = { C.TIME_UNSET, C.TIME_UNSET };
final long[] bufferedPositions = { C.TIME_UNSET, C.TIME_UNSET };
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Remove the current item.
currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
currentPositions[0] = player.getCurrentPosition();
bufferedPositions[0] = player.getBufferedPosition();
player.removeMediaItem(/* index= */
1);
currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
currentPositions[1] = player.getCurrentPosition();
bufferedPositions[1] = player.getBufferedPosition();
}
}).build();
new ExoPlayerTestRunner.Builder(context).initialSeek(/* mediaItemIndex= */
1, /* positionMs= */
5000).setMediaSources(new FakeMediaSource(), new FakeMediaSource(), new FakeMediaSource()).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertArrayEquals(new int[] { 1, 1 }, currentMediaItemIndices);
assertThat(currentPositions[0]).isAtLeast(5000L);
assertThat(bufferedPositions[0]).isAtLeast(5000L);
assertThat(currentPositions[1]).isEqualTo(0);
assertThat(bufferedPositions[1]).isAtLeast(0);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method setMediaItems_resetPosition_resetsPosition.
@Test
public void setMediaItems_resetPosition_resetsPosition() throws Exception {
final int[] currentMediaItemIndices = { C.INDEX_UNSET, C.INDEX_UNSET };
final long[] currentPositions = { C.INDEX_UNSET, C.INDEX_UNSET };
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
player.seekTo(/* mediaItemIndex= */
1, /* positionMs= */
1000);
currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
currentPositions[0] = player.getCurrentPosition();
List<MediaItem> listOfTwo = ImmutableList.of(MediaItem.fromUri(Uri.EMPTY), MediaItem.fromUri(Uri.EMPTY));
player.setMediaItems(listOfTwo, /* resetPosition= */
true);
currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
currentPositions[1] = player.getCurrentPosition();
}
}).prepare().waitForTimelineChanged().play().build();
new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start(/* doPrepare= */
false).blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertArrayEquals(new int[] { 1, 0 }, currentMediaItemIndices);
assertArrayEquals(new long[] { 1000, 0 }, currentPositions);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method seekToIndexLargerThanNumberOfPlaylistItems.
@Test
public void seekToIndexLargerThanNumberOfPlaylistItems() throws Exception {
Timeline fakeTimeline = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
10_000_000));
ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(/* isAtomic= */
false, new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT));
int[] currentMediaItemIndices = new int[1];
long[] currentPlaybackPositions = new long[1];
int seekToMediaItemIndex = 1;
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_BUFFERING).waitForTimelineChanged().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
currentPlaybackPositions[0] = player.getCurrentPosition();
}
}).build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(concatenatingMediaSource).initialSeek(seekToMediaItemIndex, 5000).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertArrayEquals(new long[] { 5_000 }, currentPlaybackPositions);
assertArrayEquals(new int[] { seekToMediaItemIndex }, currentMediaItemIndices);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method seekTo_singlePeriod_beyondBufferedData_correctMaskingPosition.
@Test
public void seekTo_singlePeriod_beyondBufferedData_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.seekTo(9200);
}
}, /* pauseMediaItemIndex= */
0, mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */
9200));
assertThat(mediaItemIndex[0]).isEqualTo(0);
assertThat(positionMs[0]).isEqualTo(9200);
assertThat(bufferedPositions[0]).isEqualTo(9200);
assertThat(totalBufferedDuration[0]).isEqualTo(0);
assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]);
assertThat(positionMs[1]).isEqualTo(positionMs[0]);
assertThat(bufferedPositions[1]).isEqualTo(9200);
assertThat(totalBufferedDuration[1]).isEqualTo(0);
}
Aggregations