use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method recursivePlayerChangesReportConsistentValuesForAllListeners.
@Test
public void recursivePlayerChangesReportConsistentValuesForAllListeners() throws Exception {
// We add two listeners to the player. The first stops the player as soon as it's ready and both
// record the state change events they receive.
final AtomicReference<Player> playerReference = new AtomicReference<>();
final List<Integer> playerListener1States = new ArrayList<>();
final List<Integer> playerListener2States = new ArrayList<>();
final Player.Listener playerListener1 = new Player.Listener() {
@Override
public void onPlaybackStateChanged(@Player.State int playbackState) {
playerListener1States.add(playbackState);
if (playbackState == Player.STATE_READY) {
playerReference.get().stop(/* reset= */
true);
}
}
};
final Player.Listener playerListener2 = new Player.Listener() {
@Override
public void onPlaybackStateChanged(@Player.State int playbackState) {
playerListener2States.add(playbackState);
}
};
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
playerReference.set(player);
player.addListener(playerListener1);
player.addListener(playerListener2);
}
}).build();
new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(playerListener1States).containsExactly(Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_IDLE).inOrder();
assertThat(playerListener2States).containsExactly(Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_IDLE).inOrder();
}
use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method addMediaSources_skipSettingMediaItems_validInitialSeek_correctMasking.
@Test
public void addMediaSources_skipSettingMediaItems_validInitialSeek_correctMasking() throws Exception {
final int[] currentMediaItemIndices = new int[5];
Arrays.fill(currentMediaItemIndices, C.INDEX_UNSET);
final long[] currentPositions = new long[3];
Arrays.fill(currentPositions, C.TIME_UNSET);
final long[] bufferedPositions = new long[3];
Arrays.fill(bufferedPositions, C.TIME_UNSET);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPositionDiscontinuity().waitForPendingPlayerCommands().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
// If the timeline is empty masking variables are used.
currentPositions[0] = player.getCurrentPosition();
bufferedPositions[0] = player.getBufferedPosition();
player.addMediaSource(/* index= */
0, new ConcatenatingMediaSource());
currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
player.addMediaSource(/* index= */
0, new FakeMediaSource(new FakeTimeline(/* windowCount= */
2)));
currentMediaItemIndices[2] = player.getCurrentMediaItemIndex();
player.addMediaSource(/* index= */
0, new FakeMediaSource());
currentMediaItemIndices[3] = player.getCurrentMediaItemIndex();
// With a non-empty timeline, we mask the periodId in the playback info.
currentPositions[1] = player.getCurrentPosition();
bufferedPositions[1] = player.getBufferedPosition();
}
}).prepare().waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
currentMediaItemIndices[4] = player.getCurrentMediaItemIndex();
// Finally original playbackInfo coming from EPII is used.
currentPositions[2] = player.getCurrentPosition();
bufferedPositions[2] = player.getBufferedPosition();
}
}).build();
new ExoPlayerTestRunner.Builder(context).skipSettingMediaSources().initialSeek(/* mediaItemIndex= */
1, 2000).setActionSchedule(actionSchedule).build().start(/* doPrepare= */
false).blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertArrayEquals(new int[] { 1, 1, 1, 2, 2 }, currentMediaItemIndices);
assertThat(currentPositions[0]).isEqualTo(2000);
assertThat(currentPositions[1]).isEqualTo(2000);
assertThat(currentPositions[2]).isAtLeast(2000);
assertThat(bufferedPositions[0]).isEqualTo(2000);
assertThat(bufferedPositions[1]).isEqualTo(2000);
assertThat(bufferedPositions[2]).isAtLeast(2000);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method seekToUnpreparedWindowWithMultiplePeriodsInConcatenationStartsAtCorrectPeriod.
@Test
public void seekToUnpreparedWindowWithMultiplePeriodsInConcatenationStartsAtCorrectPeriod() throws Exception {
long periodDurationMs = 5000;
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
2, /* id= */
new Object(), /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
2 * periodDurationMs * 1000));
FakeMediaSource mediaSource = new FakeMediaSource(/* timeline= */
null);
MediaSource concatenatedMediaSource = new ConcatenatingMediaSource(mediaSource);
AtomicInteger periodIndexWhenReady = new AtomicInteger();
AtomicLong positionWhenReady = new AtomicLong();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).seek(/* positionMs= */
periodDurationMs + 10).executeRunnable(() -> mediaSource.setNewSourceInfo(timeline)).waitForTimelineChanged().waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
periodIndexWhenReady.set(player.getCurrentPeriodIndex());
positionWhenReady.set(player.getContentPosition());
}
}).play().build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(concatenatedMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(periodIndexWhenReady.get()).isEqualTo(1);
assertThat(positionWhenReady.get()).isEqualTo(periodDurationMs + 10);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method setMediaSources_whenEnded_correctMaskingPlaybackState.
@Test
public void setMediaSources_whenEnded_correctMaskingPlaybackState() throws Exception {
Timeline firstTimeline = new FakeTimeline(/* windowCount= */
1, 1L);
MediaSource firstMediaSource = new FakeMediaSource(firstTimeline);
Timeline secondTimeline = new FakeTimeline(/* windowCount= */
1, 2L);
MediaSource secondMediaSource = new FakeMediaSource(secondTimeline);
final int[] maskingPlaybackStates = new int[4];
Arrays.fill(maskingPlaybackStates, C.INDEX_UNSET);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_ENDED).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Set empty media item with an implicit seek to the current position.
player.setMediaSource(new ConcatenatingMediaSource());
maskingPlaybackStates[0] = player.getPlaybackState();
}
}).waitForPlaybackState(Player.STATE_ENDED).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Set empty media item with an explicit seek.
player.setMediaSource(new ConcatenatingMediaSource(), /* startPositionMs= */
C.TIME_UNSET);
maskingPlaybackStates[1] = player.getPlaybackState();
}
}).waitForPlaybackState(Player.STATE_ENDED).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Set media item with an implicit seek to the current position.
player.setMediaSource(firstMediaSource);
maskingPlaybackStates[2] = player.getPlaybackState();
}
}).waitForPlaybackState(Player.STATE_READY).clearMediaItems().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Set media item with an explicit seek.
player.setMediaSource(secondMediaSource, /* startPositionMs= */
C.TIME_UNSET);
maskingPlaybackStates[3] = player.getPlaybackState();
}
}).waitForPlaybackState(Player.STATE_ENDED).build();
ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setExpectedPlayerEndedCount(/* expectedPlayerEndedCount= */
3).setMediaSources(new ConcatenatingMediaSource()).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
// Expect reset of masking to first media item.
exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_ENDED, Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED, Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED);
assertArrayEquals(new int[] { Player.STATE_ENDED, Player.STATE_ENDED, Player.STATE_BUFFERING, Player.STATE_BUFFERING }, maskingPlaybackStates);
exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.
the class ExoPlayerTest method seekTo_toLoadingPeriod_correctMaskingPosition.
@Test
public void seekTo_toLoadingPeriod_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(), new FakeMediaSource());
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(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]);
}
Aggregations