use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method clearMediaItems_unprepared_correctMaskingMediaItemIndex_notEnded.
@Test
public void clearMediaItems_unprepared_correctMaskingMediaItemIndex_notEnded() throws Exception {
final int[] currentMediaItemIndices = { C.INDEX_UNSET, C.INDEX_UNSET };
final int[] currentStates = { C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET };
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPositionDiscontinuity().waitForPendingPlayerCommands().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
currentStates[0] = player.getPlaybackState();
player.clearMediaItems();
currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
currentStates[1] = player.getPlaybackState();
}
}).prepare().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
// Transitions to ended when prepared with zero media items.
currentStates[2] = player.getPlaybackState();
}
}).build();
new ExoPlayerTestRunner.Builder(context).initialSeek(/* mediaItemIndex= */
1, /* positionMs= */
C.TIME_UNSET).setMediaSources(new FakeMediaSource(), new FakeMediaSource()).setActionSchedule(actionSchedule).build().start(/* doPrepare= */
false).blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertArrayEquals(new int[] { Player.STATE_IDLE, Player.STATE_IDLE, Player.STATE_ENDED }, currentStates);
assertArrayEquals(new int[] { 1, 0 }, currentMediaItemIndices);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class DashWidevineOfflineTest method widevineOfflineLicenseExpiresOnPauseV22.
@Test
@Ignore("Needs to be reconfigured/rewritten with an offline-compatible licence [internal" + " b/176960595].")
public void widevineOfflineLicenseExpiresOnPauseV22() throws Exception {
assumeTrue(Util.SDK_INT >= 22);
downloadLicense();
// During playback pause until the license expires then continue playback
Pair<Long, Long> licenseDurationRemainingSec = offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
long licenseDuration = licenseDurationRemainingSec.first;
assertWithMessage("License duration should be less than 30 sec. Server settings might have changed.").that(licenseDuration).isLessThan(30);
ActionSchedule schedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).delay(3000).pause().delay(licenseDuration * 1000 + 2000).play().build();
// DefaultDrmSessionManager should renew the license and stream play fine
testRunner.setActionSchedule(schedule).run();
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method prepareWhenAlreadyPreparedIsANoop.
@Test
public void prepareWhenAlreadyPreparedIsANoop() throws Exception {
Timeline timeline = new FakeTimeline();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).prepare().build();
ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED);
exoPlayerTestRunner.assertTimelinesSame(placeholderTimeline, timeline);
exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* media item set (masked timeline) */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method cancelMessageBeforeDelivery.
@Test
public void cancelMessageBeforeDelivery() throws Exception {
final PositionGrabbingMessageTarget target = new PositionGrabbingMessageTarget();
final AtomicReference<PlayerMessage> message = new AtomicReference<>();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
message.set(player.createMessage(target).setPosition(/* positionMs= */
50).send());
}
}).playUntilPosition(/* mediaItemIndex= */
0, /* positionMs= */
30).executeRunnable(() -> message.get().cancel()).play().build();
new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(message.get().isCanceled()).isTrue();
assertThat(target.messageCount).isEqualTo(0);
}
use of com.google.android.exoplayer2.testutil.ActionSchedule in project ExoPlayer by google.
the class ExoPlayerTest method removeMediaItem.
@Test
public void removeMediaItem() throws Exception {
TimelineWindowDefinition firstWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(10000));
TimelineWindowDefinition secondWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
2, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(10000));
TimelineWindowDefinition thirdWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
3, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(10000));
Timeline timeline1 = new FakeTimeline(firstWindowDefinition);
Timeline timeline2 = new FakeTimeline(secondWindowDefinition);
Timeline timeline3 = new FakeTimeline(thirdWindowDefinition);
MediaSource mediaSource1 = new FakeMediaSource(timeline1);
MediaSource mediaSource2 = new FakeMediaSource(timeline2);
MediaSource mediaSource3 = new FakeMediaSource(timeline3);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).removeMediaItem(/* index= */
0).build();
ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource1, mediaSource2, mediaSource3).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
Timeline expectedPlaceholderTimeline = new FakeTimeline(TimelineWindowDefinition.createPlaceholder(/* tag= */
1), TimelineWindowDefinition.createPlaceholder(/* tag= */
2), TimelineWindowDefinition.createPlaceholder(/* tag= */
3));
Timeline expectedRealTimeline = new FakeTimeline(firstWindowDefinition, secondWindowDefinition, thirdWindowDefinition);
Timeline expectedRealTimelineAfterRemove = new FakeTimeline(secondWindowDefinition, thirdWindowDefinition);
exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
exoPlayerTestRunner.assertTimelinesSame(expectedPlaceholderTimeline, expectedRealTimeline, expectedRealTimelineAfterRemove);
}
Aggregations