use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method emptyMultiWindowMediaSource_doesNotEnterBufferState.
@Test
public void emptyMultiWindowMediaSource_doesNotEnterBufferState() throws Exception {
ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(/* isAtomic= */
false);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_ENDED).build();
ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(concatenatingMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_ENDED);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method seekTo_whilePlayingAd_correctMasking.
@Test
public void seekTo_whilePlayingAd_correctMasking() throws Exception {
long contentDurationMs = 10_000;
long adDurationMs = 4_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 };
long[] positionMs = new long[] { C.TIME_UNSET, C.TIME_UNSET };
long[] bufferedPositionMs = new long[] { C.TIME_UNSET, C.TIME_UNSET };
long[] totalBufferedDurationMs = new long[] { C.TIME_UNSET, C.TIME_UNSET };
boolean[] isPlayingAd = new boolean[2];
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).waitForIsLoading(true).waitForIsLoading(false).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
player.seekTo(/* mediaItemIndex= */
0, /* positionMs= */
8000);
mediaItemIndex[0] = player.getCurrentMediaItemIndex();
isPlayingAd[0] = player.isPlayingAd();
positionMs[0] = player.getCurrentPosition();
bufferedPositionMs[0] = player.getBufferedPosition();
totalBufferedDurationMs[0] = player.getTotalBufferedDuration();
}
}).waitForPendingPlayerCommands().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();
}
}).stop().build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(adsMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertThat(mediaItemIndex[0]).isEqualTo(0);
assertThat(isPlayingAd[0]).isTrue();
assertThat(positionMs[0]).isEqualTo(0);
assertThat(bufferedPositionMs[0]).isEqualTo(adDurationMs);
assertThat(totalBufferedDurationMs[0]).isEqualTo(adDurationMs);
assertThat(mediaItemIndex[1]).isEqualTo(0);
assertThat(isPlayingAd[1]).isTrue();
assertThat(positionMs[1]).isEqualTo(0);
assertThat(bufferedPositionMs[1]).isEqualTo(adDurationMs);
assertThat(totalBufferedDurationMs[1]).isEqualTo(adDurationMs);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method mediaItemOfSources_correctInTimelineWindows.
@Test
public void mediaItemOfSources_correctInTimelineWindows() throws Exception {
TimelineWindowDefinition window1 = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1, /* isSeekable= */
true, /* isDynamic= */
false, /* isLive= */
false, /* isPlaceholder= */
false, /* durationUs = */
100_000, /* defaultPositionUs = */
0, /* windowOffsetInFirstPeriodUs= */
0, ImmutableList.of(AdPlaybackState.NONE), MediaItem.fromUri("http://foo.bar/fake1"));
FakeMediaSource fakeMediaSource1 = new FakeMediaSource(new FakeTimeline(window1));
TimelineWindowDefinition window2 = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
2, /* isSeekable= */
true, /* isDynamic= */
false, /* isLive= */
false, /* isPlaceholder= */
false, /* durationUs = */
100_000, /* defaultPositionUs = */
0, /* windowOffsetInFirstPeriodUs= */
0, ImmutableList.of(AdPlaybackState.NONE), MediaItem.fromUri("http://foo.bar/fake2"));
FakeMediaSource fakeMediaSource2 = new FakeMediaSource(new FakeTimeline(window2));
TimelineWindowDefinition window3 = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
3, /* isSeekable= */
true, /* isDynamic= */
false, /* isLive= */
false, /* isPlaceholder= */
false, /* durationUs = */
100_000, /* defaultPositionUs = */
0, /* windowOffsetInFirstPeriodUs= */
0, ImmutableList.of(AdPlaybackState.NONE), MediaItem.fromUri("http://foo.bar/fake3"));
FakeMediaSource fakeMediaSource3 = new FakeMediaSource(new FakeTimeline(window3));
final Player[] playerHolder = { null };
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
playerHolder[0] = player;
}
}).waitForPlaybackState(Player.STATE_READY).seek(/* positionMs= */
0).play().build();
List<MediaItem> currentMediaItems = new ArrayList<>();
List<MediaItem> mediaItemsInTimeline = new ArrayList<>();
Player.Listener playerListener = new Player.Listener() {
@Override
public void onTimelineChanged(Timeline timeline, int reason) {
if (reason != Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED) {
return;
}
Window window = new Window();
for (int i = 0; i < timeline.getWindowCount(); i++) {
mediaItemsInTimeline.add(timeline.getWindow(i, window).mediaItem);
}
}
@Override
public void onPositionDiscontinuity(int reason) {
if (reason == Player.DISCONTINUITY_REASON_SEEK || reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
currentMediaItems.add(playerHolder[0].getCurrentMediaItem());
}
}
};
new ExoPlayerTestRunner.Builder(context).setPlayerListener(playerListener).setActionSchedule(actionSchedule).setMediaSources(fakeMediaSource1, fakeMediaSource2, fakeMediaSource3).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertThat(currentMediaItems.get(0).localConfiguration.uri.toString()).isEqualTo("http://foo.bar/fake1");
assertThat(currentMediaItems.get(1).localConfiguration.uri.toString()).isEqualTo("http://foo.bar/fake2");
assertThat(currentMediaItems.get(2).localConfiguration.uri.toString()).isEqualTo("http://foo.bar/fake3");
assertThat(mediaItemsInTimeline).containsExactlyElementsIn(currentMediaItems);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method setShuffleMode_correctPositionMasking.
@Test
public void setShuffleMode_correctPositionMasking() throws Exception {
long[] currentPositionMs = new long[] { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
long[] bufferedPositionMs = new long[] { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).playUntilPosition(0, 5000).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
currentPositionMs[0] = player.getCurrentPosition();
bufferedPositionMs[0] = player.getBufferedPosition();
player.setShuffleModeEnabled(true);
currentPositionMs[1] = player.getCurrentPosition();
bufferedPositionMs[1] = player.getBufferedPosition();
player.setShuffleModeEnabled(false);
currentPositionMs[2] = player.getCurrentPosition();
bufferedPositionMs[2] = player.getBufferedPosition();
}
}).play().build();
new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(currentPositionMs[0]).isAtLeast(5000);
assertThat(currentPositionMs[1]).isEqualTo(currentPositionMs[0]);
assertThat(currentPositionMs[2]).isEqualTo(currentPositionMs[0]);
assertThat(bufferedPositionMs[0]).isGreaterThan(currentPositionMs[0]);
assertThat(bufferedPositionMs[1]).isEqualTo(bufferedPositionMs[0]);
assertThat(bufferedPositionMs[2]).isEqualTo(bufferedPositionMs[0]);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method setMediaSources_whenEnded_noSeek_correctMaskingPlaybackState.
@Test
public void setMediaSources_whenEnded_noSeek_correctMaskingPlaybackState() throws Exception {
final int[] maskingPlaybackStates = new int[1];
Arrays.fill(maskingPlaybackStates, C.INDEX_UNSET);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).clearMediaItems().waitForPlaybackState(Player.STATE_ENDED).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Set media item with no seek (keep current position).
player.setMediaSource(new FakeMediaSource(), /* resetPosition= */
false);
maskingPlaybackStates[0] = player.getPlaybackState();
}
}).waitForTimelineChanged().waitForPlaybackState(Player.STATE_ENDED).build();
ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
// Expect reset of masking to first media item.
exoPlayerTestRunner.assertPlaybackStatesEqual(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_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
Aggregations