use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method sendMessagesSeekAfterDeliveryTimeDuringPreparation.
@Test
public void sendMessagesSeekAfterDeliveryTimeDuringPreparation() throws Exception {
PositionGrabbingMessageTarget target = new PositionGrabbingMessageTarget();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).sendMessage(target, /* positionMs= */
50).seek(/* positionMs= */
51).play().build();
new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(target.positionMs).isEqualTo(C.POSITION_UNSET);
}
use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class DefaultAnalyticsCollectorTest method prepareNewSource.
@Test
public void prepareNewSource() throws Exception {
MediaSource mediaSource1 = new FakeMediaSource(SINGLE_PERIOD_TIMELINE, ExoPlayerTestRunner.VIDEO_FORMAT);
MediaSource mediaSource2 = new FakeMediaSource(SINGLE_PERIOD_TIMELINE, ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).setMediaSources(/* resetPosition= */
false, mediaSource2).waitForTimelineChanged().waitForIsLoading(true).play().build();
TestAnalyticsListener listener = runAnalyticsTest(mediaSource1, actionSchedule);
// Populate all event ids with last timeline (after second prepare).
populateEventIds(listener.lastReportedTimeline);
// Populate event id of period 0, sequence 0 with timeline of initial preparation.
period0Seq0 = new EventWindowAndPeriodId(/* windowIndex= */
0, new MediaPeriodId(listener.reportedTimelines.get(1).getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0));
assertThat(listener.getEvents(EVENT_PLAYER_STATE_CHANGED)).containsExactly(WINDOW_0, /* setPlayWhenReady=true */
WINDOW_0, /* BUFFERING */
WINDOW_0, /* setPlayWhenReady=false */
period0Seq0, /* READY */
WINDOW_0, /* BUFFERING */
period0Seq1, /* setPlayWhenReady=true */
period0Seq1, /* READY */
period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)).containsExactly(WINDOW_0, /* PLAYLIST_CHANGE */
period0Seq0, /* SOURCE_UPDATE */
WINDOW_0, /* PLAYLIST_CHANGE */
period0Seq1);
assertThat(listener.getEvents(EVENT_POSITION_DISCONTINUITY)).containsExactly(WINDOW_0);
assertThat(listener.getEvents(EVENT_IS_LOADING_CHANGED)).containsExactly(period0Seq0, period0Seq0, period0Seq1, period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(period0Seq0, /* prepared */
WINDOW_0, /* setMediaSources */
period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_LOAD_STARTED)).containsExactly(WINDOW_0, /* manifest */
period0Seq0, /* media */
WINDOW_0, /* manifest */
period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)).containsExactly(WINDOW_0, /* manifest */
period0Seq0, /* media */
WINDOW_0, /* manifest */
period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)).containsExactly(period0Seq0, period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_ENABLED)).containsExactly(period0Seq0, period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_INIT)).containsExactly(period0Seq0, period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_FORMAT_CHANGED)).containsExactly(period0Seq0, period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(period0Seq0);
assertThat(listener.getEvents(EVENT_VIDEO_ENABLED)).containsExactly(period0Seq0, period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(period0Seq0, period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(period0Seq0, period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(period0Seq0);
assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(period0Seq1);
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(period0Seq0, period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(period0Seq0, period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).containsExactly(period0Seq1);
listener.assertNoMoreEvents();
}
use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class DefaultAnalyticsCollectorTest method seekBackAfterReadingAhead.
@Test
public void seekBackAfterReadingAhead() throws Exception {
MediaSource mediaSource = new ConcatenatingMediaSource(new FakeMediaSource(SINGLE_PERIOD_TIMELINE, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(SINGLE_PERIOD_TIMELINE, ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.AUDIO_FORMAT));
long periodDurationMs = SINGLE_PERIOD_TIMELINE.getWindow(/* windowIndex= */
0, new Window()).getDurationMs();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).playUntilPosition(/* mediaItemIndex= */
0, periodDurationMs).seekAndWait(/* positionMs= */
0).play().build();
TestAnalyticsListener listener = runAnalyticsTest(mediaSource, actionSchedule);
populateEventIds(listener.lastReportedTimeline);
assertThat(listener.getEvents(EVENT_PLAYER_STATE_CHANGED)).containsExactly(WINDOW_0, /* setPlayWhenReady=true */
WINDOW_0, /* setPlayWhenReady=false */
WINDOW_0, /* BUFFERING */
period0, /* READY */
period0, /* setPlayWhenReady=true */
period0, /* setPlayWhenReady=false */
period0, /* BUFFERING */
period0, /* READY */
period0, /* setPlayWhenReady=true */
period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)).containsExactly(WINDOW_0, /* PLAYLIST_CHANGED */
period0).inOrder();
assertThat(listener.getEvents(EVENT_POSITION_DISCONTINUITY)).containsExactly(period0, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_SEEK_STARTED)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_SEEK_PROCESSED)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_IS_LOADING_CHANGED)).containsExactly(period0, period0, period0, period0).inOrder();
assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(period0, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_LOAD_STARTED)).containsExactly(WINDOW_0, /* manifest */
WINDOW_1, /* manifest */
period0, /* media */
period1Seq1, /* media */
period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)).containsExactly(WINDOW_0, /* manifest */
WINDOW_1, /* manifest */
period0, /* media */
period1Seq1, /* media */
period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)).containsExactly(period0, period1Seq1, period1Seq1, period1Seq2, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_ENABLED)).containsExactly(period0, period1, period0, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_INIT)).containsExactly(period0, period1Seq1, period1Seq1, period1Seq2, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_FORMAT_CHANGED)).containsExactly(period0, period1Seq1, period1Seq1, period1Seq2, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(period0, period0);
assertThat(listener.getEvents(EVENT_AUDIO_ENABLED)).containsExactly(period1, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_AUDIO_DECODER_INITIALIZED)).containsExactly(period1Seq1, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_AUDIO_INPUT_FORMAT_CHANGED)).containsExactly(period1Seq1, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_AUDIO_POSITION_ADVANCING)).containsExactly(period1Seq1, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_AUDIO_DISABLED)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_VIDEO_ENABLED)).containsExactly(period0, period0);
assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(period0, period1Seq1, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(period0, period1Seq1, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(period0, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(period0, period1Seq1, period0, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(period0, period1Seq1, period0, period1Seq2).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).containsExactly(period0, period1Seq2).inOrder();
listener.assertNoMoreEvents();
}
use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class DefaultAnalyticsCollectorTest method dynamicTimelineChange.
@Test
public void dynamicTimelineChange() throws Exception {
MediaSource childMediaSource = new FakeMediaSource(SINGLE_PERIOD_TIMELINE, ExoPlayerTestRunner.VIDEO_FORMAT);
final ConcatenatingMediaSource concatenatedMediaSource = new ConcatenatingMediaSource(childMediaSource, childMediaSource);
long periodDurationMs = SINGLE_PERIOD_TIMELINE.getWindow(/* windowIndex= */
0, new Window()).getDurationMs();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).playUntilPosition(/* mediaItemIndex= */
0, /* positionMs= */
periodDurationMs).executeRunnable(() -> concatenatedMediaSource.moveMediaSource(/* currentIndex= */
0, /* newIndex= */
1)).waitForTimelineChanged().waitForPlaybackState(Player.STATE_READY).play().build();
TestAnalyticsListener listener = runAnalyticsTest(concatenatedMediaSource, actionSchedule);
populateEventIds(listener.lastReportedTimeline);
assertThat(listener.getEvents(EVENT_PLAYER_STATE_CHANGED)).containsExactly(WINDOW_0, /* setPlayWhenReady=true */
WINDOW_0, /* setPlayWhenReady=false */
WINDOW_0, /* BUFFERING */
window0Period1Seq0, /* READY */
window0Period1Seq0, /* setPlayWhenReady=true */
window0Period1Seq0, /* setPlayWhenReady=false */
period1Seq0, /* setPlayWhenReady=true */
period1Seq0, /* BUFFERING */
period1Seq0, /* READY */
period1Seq0).inOrder();
assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)).containsExactly(WINDOW_0, /* PLAYLIST_CHANGED */
window0Period1Seq0, /* SOURCE_UPDATE (concatenated timeline replaces placeholder) */
period1Seq0).inOrder();
assertThat(listener.getEvents(EVENT_IS_LOADING_CHANGED)).containsExactly(window0Period1Seq0, window0Period1Seq0, period1Seq0, period1Seq0);
assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(window0Period1Seq0);
assertThat(listener.getEvents(EVENT_LOAD_STARTED)).containsExactly(WINDOW_0, /* manifest */
window0Period1Seq0, /* media */
window1Period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)).containsExactly(WINDOW_0, /* manifest */
window0Period1Seq0, /* media */
window1Period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)).containsExactly(window0Period1Seq0, window1Period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_ENABLED)).containsExactly(window0Period1Seq0, window0Period1Seq0).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_INIT)).containsExactly(window0Period1Seq0, window1Period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_FORMAT_CHANGED)).containsExactly(window0Period1Seq0, window1Period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(window0Period1Seq0);
assertThat(listener.getEvents(EVENT_VIDEO_ENABLED)).containsExactly(window0Period1Seq0, window0Period1Seq0).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(window0Period1Seq0, window1Period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(window0Period1Seq0, window1Period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(window0Period1Seq0);
assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(window0Period1Seq0, period1Seq0).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(window0Period1Seq0, window1Period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(window0Period1Seq0, window1Period0Seq1).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).containsExactly(window0Period1Seq0, period1Seq0).inOrder();
listener.assertNoMoreEvents();
}
use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method addMediaSource_whilePlayingAd_correctMasking.
@Test
public void addMediaSource_whilePlayingAd_correctMasking() throws Exception {
long contentDurationMs = 10_000;
long adDurationMs = 100_000;
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
new Object(), /* adGroupTimesUs...= */
0);
adPlaybackState = adPlaybackState.withAdCount(/* adGroupIndex= */
0, /* adCount= */
1);
adPlaybackState = adPlaybackState.withAdUri(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, Uri.EMPTY);
long[][] durationsUs = new long[1][];
durationsUs[0] = new long[] { Util.msToUs(adDurationMs) };
adPlaybackState = adPlaybackState.withAdDurationsUs(durationsUs);
Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(contentDurationMs), adPlaybackState));
FakeMediaSource adsMediaSource = new FakeMediaSource(adTimeline);
int[] mediaItemIndex = new int[] { C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET };
long[] positionMs = new long[] { C.TIME_UNSET, C.TIME_UNSET, C.INDEX_UNSET };
long[] bufferedPositionMs = new long[] { C.TIME_UNSET, C.TIME_UNSET, C.INDEX_UNSET };
long[] totalBufferedDurationMs = new long[] { C.TIME_UNSET, C.TIME_UNSET, C.INDEX_UNSET };
boolean[] isPlayingAd = new boolean[3];
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForIsLoading(true).waitForIsLoading(false).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
player.addMediaSource(/* index= */
1, new FakeMediaSource());
mediaItemIndex[0] = player.getCurrentMediaItemIndex();
isPlayingAd[0] = player.isPlayingAd();
positionMs[0] = player.getCurrentPosition();
bufferedPositionMs[0] = player.getBufferedPosition();
totalBufferedDurationMs[0] = player.getTotalBufferedDuration();
}
}).waitForTimelineChanged().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
mediaItemIndex[1] = player.getCurrentMediaItemIndex();
isPlayingAd[1] = player.isPlayingAd();
positionMs[1] = player.getCurrentPosition();
bufferedPositionMs[1] = player.getBufferedPosition();
totalBufferedDurationMs[1] = player.getTotalBufferedDuration();
}
}).playUntilPosition(/* mediaItemIndex= */
0, /* positionMs= */
8000).waitForPendingPlayerCommands().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
player.addMediaSource(new FakeMediaSource());
mediaItemIndex[2] = player.getCurrentMediaItemIndex();
isPlayingAd[2] = player.isPlayingAd();
positionMs[2] = player.getCurrentPosition();
bufferedPositionMs[2] = player.getBufferedPosition();
totalBufferedDurationMs[2] = player.getTotalBufferedDuration();
}
}).play().build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(adsMediaSource, new FakeMediaSource()).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertThat(mediaItemIndex[0]).isEqualTo(0);
assertThat(isPlayingAd[0]).isTrue();
assertThat(positionMs[0]).isAtMost(adDurationMs);
assertThat(bufferedPositionMs[0]).isEqualTo(adDurationMs);
assertThat(totalBufferedDurationMs[0]).isAtLeast(adDurationMs - positionMs[0]);
assertThat(mediaItemIndex[1]).isEqualTo(0);
assertThat(isPlayingAd[1]).isTrue();
assertThat(positionMs[1]).isAtMost(adDurationMs);
assertThat(bufferedPositionMs[1]).isEqualTo(adDurationMs);
assertThat(totalBufferedDurationMs[1]).isAtLeast(adDurationMs - positionMs[1]);
assertThat(mediaItemIndex[2]).isEqualTo(0);
assertThat(isPlayingAd[2]).isFalse();
assertThat(positionMs[2]).isEqualTo(8000);
assertThat(bufferedPositionMs[2]).isEqualTo(contentDurationMs);
assertThat(totalBufferedDurationMs[2]).isAtLeast(contentDurationMs - positionMs[2]);
}
Aggregations