use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method setMediaSources_whenPrepared_correctMaskingPlaybackState.
@Test
public void setMediaSources_whenPrepared_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).pause().waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Set empty media item with an implicit seek to current position.
player.setMediaSource(new ConcatenatingMediaSource(), /* resetPosition= */
false);
// Expect masking state is ended,
maskingPlaybackStates[0] = player.getPlaybackState();
}
}).waitForPlaybackState(Player.STATE_ENDED).setMediaSources(/* mediaItemIndex= */
0, /* positionMs= */
C.TIME_UNSET, firstMediaSource).waitForPlaybackState(Player.STATE_READY).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);
// Expect masking state is ended,
maskingPlaybackStates[1] = player.getPlaybackState();
}
}).waitForPlaybackState(Player.STATE_ENDED).setMediaSources(/* mediaItemIndex= */
0, /* positionMs= */
C.TIME_UNSET, firstMediaSource).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Set media item with an explicit seek.
player.setMediaSource(secondMediaSource, /* startPositionMs= */
C.TIME_UNSET);
// Expect masking state is buffering,
maskingPlaybackStates[2] = player.getPlaybackState();
}
}).waitForPlaybackState(Player.STATE_READY).setMediaSources(/* mediaItemIndex= */
0, /* positionMs= */
C.TIME_UNSET, firstMediaSource).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Set media item with an implicit seek to the current position.
player.setMediaSource(secondMediaSource, /* resetPosition= */
false);
// Expect masking state is buffering,
maskingPlaybackStates[3] = player.getPlaybackState();
}
}).play().waitForPlaybackState(Player.STATE_READY).build();
ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setExpectedPlayerEndedCount(/* expectedPlayerEndedCount= */
3).setMediaSources(firstMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
// Expect reset of masking to first media item.
exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_BUFFERING, // Ready after initial prepare.
Player.STATE_READY, // Ended after setting empty source without seek.
Player.STATE_ENDED, Player.STATE_BUFFERING, // Ready again after re-setting source.
Player.STATE_READY, // Ended after setting empty source with seek.
Player.STATE_ENDED, Player.STATE_BUFFERING, // Ready again after re-setting source.
Player.STATE_READY, Player.STATE_BUFFERING, // Ready after setting media item with seek.
Player.STATE_READY, Player.STATE_BUFFERING, // Ready again after re-setting source.
Player.STATE_READY, // Play.
Player.STATE_BUFFERING, // Ready after setting media item without seek.
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, // Initial source.
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, // Empty source.
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, // Reset source.
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, // Empty source.
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, // Reset source.
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, // Set source with seek.
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, // Reset source.
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, // Set source without seek.
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method stop_withoutReset_releasesMediaSource.
@Test
public void stop_withoutReset_releasesMediaSource() throws Exception {
Timeline timeline = new FakeTimeline();
final FakeMediaSource mediaSource = new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).stop(/* reset= */
false).build();
new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
mediaSource.assertReleased();
}
use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method timelineUpdateWithNewMidrollAdCuePoint_dropsPrebufferedPeriod.
@Test
public void timelineUpdateWithNewMidrollAdCuePoint_dropsPrebufferedPeriod() throws Exception {
Timeline timeline1 = new FakeTimeline(TimelineWindowDefinition.createPlaceholder(/* tag= */
0));
AdPlaybackState adPlaybackStateWithMidroll = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
1, /* adGroupTimesUs...= */
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 5 * C.MICROS_PER_SECOND);
Timeline timeline2 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
10_000_000, adPlaybackStateWithMidroll));
FakeMediaSource mediaSource = new FakeMediaSource(timeline1, ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).executeRunnable(() -> mediaSource.setNewSourceInfo(timeline2)).waitForTimelineChanged(timeline2, /* expectedReason= */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).play().build();
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
testRunner.assertPlayedPeriodIndices(0);
testRunner.assertPositionDiscontinuityReasonsEqual(Player.DISCONTINUITY_REASON_AUTO_TRANSITION, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
assertThat(mediaSource.getCreatedMediaPeriods()).hasSize(4);
assertThat(mediaSource.getCreatedMediaPeriods().get(0).nextAdGroupIndex).isEqualTo(C.INDEX_UNSET);
assertThat(mediaSource.getCreatedMediaPeriods().get(1).nextAdGroupIndex).isEqualTo(0);
assertThat(mediaSource.getCreatedMediaPeriods().get(2).adGroupIndex).isEqualTo(0);
assertThat(mediaSource.getCreatedMediaPeriods().get(3).adGroupIndex).isEqualTo(C.INDEX_UNSET);
}
use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method setUnsupportedPlaybackSpeedConsecutivelyNotifiesListenerForEveryChangeOnceAndResetsOnceHandled.
@Test
public void setUnsupportedPlaybackSpeedConsecutivelyNotifiesListenerForEveryChangeOnceAndResetsOnceHandled() throws Exception {
Renderer renderer = new FakeMediaClockRenderer(C.TRACK_TYPE_AUDIO) {
@Override
public long getPositionUs() {
return 0;
}
@Override
public void setPlaybackParameters(PlaybackParameters playbackParameters) {
}
@Override
public PlaybackParameters getPlaybackParameters() {
return PlaybackParameters.DEFAULT;
}
};
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).setPlaybackParameters(new PlaybackParameters(/* speed= */
1.1f)).setPlaybackParameters(new PlaybackParameters(/* speed= */
1.2f)).setPlaybackParameters(new PlaybackParameters(/* speed= */
1.3f)).play().build();
List<PlaybackParameters> reportedPlaybackParameters = new ArrayList<>();
Player.Listener listener = new Player.Listener() {
@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
reportedPlaybackParameters.add(playbackParameters);
}
};
new ExoPlayerTestRunner.Builder(context).setSupportedFormats(ExoPlayerTestRunner.AUDIO_FORMAT).setRenderers(renderer).setActionSchedule(actionSchedule).setPlayerListener(listener).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(reportedPlaybackParameters).containsExactly(new PlaybackParameters(/* speed= */
1.1f), new PlaybackParameters(/* speed= */
1.2f), new PlaybackParameters(/* speed= */
1.3f), PlaybackParameters.DEFAULT).inOrder();
}
use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method sendMessagesSeekAfterDeliveryTimeAfterPreparation.
@Test
public void sendMessagesSeekAfterDeliveryTimeAfterPreparation() throws Exception {
Timeline timeline = new FakeTimeline();
PositionGrabbingMessageTarget target = new PositionGrabbingMessageTarget();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().sendMessage(target, /* positionMs= */
50).waitForTimelineChanged(timeline, /* expectedReason */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).seek(/* positionMs= */
51).play().build();
new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(target.positionMs).isEqualTo(C.POSITION_UNSET);
}
Aggregations