use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method sendMessagesRepeatWithoutDeletingDoesRepost.
@Test
public void sendMessagesRepeatWithoutDeletingDoesRepost() throws Exception {
PositionGrabbingMessageTarget target = new PositionGrabbingMessageTarget();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).sendMessage(target, /* mediaItemIndex= */
0, /* positionMs= */
50, /* deleteAfterDelivery= */
false).setRepeatMode(Player.REPEAT_MODE_ALL).playUntilPosition(/* mediaItemIndex= */
0, /* positionMs= */
1).playUntilStartOfMediaItem(/* mediaItemIndex= */
0).setRepeatMode(Player.REPEAT_MODE_OFF).play().build();
new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(target.messageCount).isEqualTo(2);
assertThat(target.positionMs).isAtLeast(50L);
}
use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method periodTransitionReportsCorrectBufferedPosition.
@Test
public void periodTransitionReportsCorrectBufferedPosition() throws Exception {
int periodCount = 3;
long periodDurationUs = 5 * C.MICROS_PER_SECOND;
long windowDurationUs = periodCount * periodDurationUs;
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(periodCount, /* id= */
new Object(), /* isSeekable= */
true, /* isDynamic= */
false, windowDurationUs));
AtomicReference<Player> playerReference = new AtomicReference<>();
AtomicLong bufferedPositionAtFirstDiscontinuityMs = new AtomicLong(C.TIME_UNSET);
Player.Listener playerListener = new Player.Listener() {
@Override
public void onPositionDiscontinuity(@DiscontinuityReason int reason) {
if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
if (bufferedPositionAtFirstDiscontinuityMs.get() == C.TIME_UNSET) {
bufferedPositionAtFirstDiscontinuityMs.set(playerReference.get().getBufferedPosition());
}
}
}
};
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
playerReference.set(player);
player.addListener(playerListener);
}
}).pause().waitForIsLoading(/* targetIsLoading= */
true).waitForIsLoading(/* targetIsLoading= */
false).play().build();
new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(bufferedPositionAtFirstDiscontinuityMs.get()).isEqualTo(Util.usToMs(windowDurationUs));
}
use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method setMediaSources_whenPrepared_invalidSeek_correctMaskingPlaybackState.
@Test
public void setMediaSources_whenPrepared_invalidSeek_correctMaskingPlaybackState() throws Exception {
Timeline firstTimeline = new FakeTimeline(/* windowCount= */
1, 1L);
MediaSource firstMediaSource = new FakeMediaSource(firstTimeline);
final int[] maskingPlaybackStates = new int[1];
Arrays.fill(maskingPlaybackStates, C.INDEX_UNSET);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_ENDED).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// An implicit, invalid seek picking up the position set by the initial seek.
player.setMediaSource(firstMediaSource, /* resetPosition= */
false);
// Expect masking state is ended,
maskingPlaybackStates[0] = player.getPlaybackState();
}
}).waitForTimelineChanged().setMediaSources(/* mediaItemIndex= */
0, /* positionMs= */
C.TIME_UNSET, firstMediaSource).waitForPlaybackState(Player.STATE_READY).play().waitForPlaybackState(Player.STATE_ENDED).build();
ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setExpectedPlayerEndedCount(/* expectedPlayerEndedCount= */
2).initialSeek(/* mediaItemIndex= */
1, /* positionMs= */
C.TIME_UNSET).setMediaSources(new ConcatenatingMediaSource()).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
// Expect reset of masking to first media item.
exoPlayerTestRunner.assertPlaybackStatesEqual(// Empty source has been prepared.
Player.STATE_ENDED, // After setting another source.
Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED);
assertArrayEquals(new int[] { Player.STATE_ENDED }, 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_SOURCE_UPDATE);
}
use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method setMediaSources_whenEmpty_correctMaskingMediaItemIndex.
@Test
public void setMediaSources_whenEmpty_correctMaskingMediaItemIndex() throws Exception {
final int[] currentMediaItemIndices = { 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) {
// Increase current media item index.
player.addMediaSource(/* index= */
0, new FakeMediaSource());
currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
}
}).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Current media item index is unchanged.
player.addMediaSource(/* index= */
2, new FakeMediaSource());
currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
}
}).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
MediaSource mediaSource = new FakeMediaSource();
ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(mediaSource, mediaSource, mediaSource);
// Increase current media item with multi media item source.
player.addMediaSource(/* index= */
0, concatenatingMediaSource);
currentMediaItemIndices[2] = player.getCurrentMediaItemIndex();
}
}).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource();
// Current media item index is unchanged when adding empty source.
player.addMediaSource(/* index= */
0, concatenatingMediaSource);
currentMediaItemIndices[3] = player.getCurrentMediaItemIndex();
}
}).build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(new FakeMediaSource()).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertArrayEquals(new int[] { 1, 1, 4, 4 }, currentMediaItemIndices);
}
use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class DefaultAnalyticsCollectorTest method onPlayerError_thrownDuringRendererReplaceStreamAtPeriodTransition_isReportedForNewPeriod.
@Test
public void onPlayerError_thrownDuringRendererReplaceStreamAtPeriodTransition_isReportedForNewPeriod() throws Exception {
FakeMediaSource source = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.AUDIO_FORMAT);
RenderersFactory renderersFactory = (eventHandler, videoListener, audioListener, textOutput, metadataOutput) -> new Renderer[] { new FakeRenderer(C.TRACK_TYPE_AUDIO) {
private int streamChangeCount = 0;
@Override
protected void onStreamChanged(Format[] formats, long startPositionUs, long offsetUs) throws ExoPlaybackException {
// period transition (as the first time is when enabling the stream initially).
if (++streamChangeCount == 2) {
throw createRendererException(new IllegalStateException(), ExoPlayerTestRunner.AUDIO_FORMAT, PlaybackException.ERROR_CODE_UNSPECIFIED);
}
}
} };
TestAnalyticsListener listener = runAnalyticsTest(new ConcatenatingMediaSource(source, source), /* actionSchedule= */
null, renderersFactory);
populateEventIds(listener.lastReportedTimeline);
assertThat(listener.getEvents(EVENT_PLAYER_ERROR)).containsExactly(period1);
}
Aggregations