use of com.google.android.exoplayer2.testutil.ExoPlayerTestRunner in project ExoPlayer by google.
the class ExoPlayerTest method playbackErrorTwiceStillKeepsTimeline.
@Test
public void playbackErrorTwiceStillKeepsTimeline() throws Exception {
final Timeline timeline = new FakeTimeline();
final FakeMediaSource mediaSource2 = new FakeMediaSource(timeline);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).throwPlaybackException(ExoPlaybackException.createForSource(new IOException(), PlaybackException.ERROR_CODE_IO_UNSPECIFIED)).waitForPlaybackState(Player.STATE_IDLE).setMediaSources(/* resetPosition= */
false, mediaSource2).prepare().waitForPlaybackState(Player.STATE_BUFFERING).throwPlaybackException(ExoPlaybackException.createForSource(new IOException(), PlaybackException.ERROR_CODE_IO_UNSPECIFIED)).waitForTimelineChanged(timeline, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).waitForPlaybackState(Player.STATE_IDLE).build();
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build();
try {
testRunner.start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
fail();
} catch (ExoPlaybackException e) {
// Expected exception.
}
testRunner.assertTimelinesSame(placeholderTimeline, timeline, placeholderTimeline, timeline);
testRunner.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.testutil.ExoPlayerTestRunner in project ExoPlayer by google.
the class ExoPlayerTest method reprepareAfterPlaybackError.
@Test
public void reprepareAfterPlaybackError() throws Exception {
Timeline timeline = new FakeTimeline();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).throwPlaybackException(ExoPlaybackException.createForSource(new IOException(), PlaybackException.ERROR_CODE_IO_UNSPECIFIED)).waitForPlaybackState(Player.STATE_IDLE).prepare().waitForPlaybackState(Player.STATE_BUFFERING).build();
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build();
try {
testRunner.start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
fail();
} catch (ExoPlaybackException e) {
// Expected exception.
}
testRunner.assertTimelinesSame(placeholderTimeline, timeline);
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
use of com.google.android.exoplayer2.testutil.ExoPlayerTestRunner in project ExoPlayer by google.
the class ExoPlayerTest method delegatingMediaSourceApproach.
@Test
public void delegatingMediaSourceApproach() throws Exception {
Timeline fakeTimeline = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
10_000_000));
final ConcatenatingMediaSource underlyingSource = new ConcatenatingMediaSource();
CompositeMediaSource<Void> delegatingMediaSource = new CompositeMediaSource<Void>() {
@Override
public void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
super.prepareSourceInternal(mediaTransferListener);
underlyingSource.addMediaSource(new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT));
underlyingSource.addMediaSource(new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT));
prepareChildSource(null, underlyingSource);
}
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
return underlyingSource.createPeriod(id, allocator, startPositionUs);
}
@Override
public void releasePeriod(MediaPeriod mediaPeriod) {
underlyingSource.releasePeriod(mediaPeriod);
}
@Override
protected void onChildSourceInfoRefreshed(Void id, MediaSource mediaSource, Timeline timeline) {
refreshSourceInfo(timeline);
}
@Override
public boolean isSingleWindow() {
return false;
}
@Override
public MediaItem getMediaItem() {
return underlyingSource.getMediaItem();
}
@Override
@Nullable
public Timeline getInitialTimeline() {
return Timeline.EMPTY;
}
};
int[] currentMediaItemIndices = new int[1];
long[] currentPlaybackPositions = new long[1];
long[] windowCounts = new long[1];
int seekToMediaItemIndex = 1;
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).seek(/* mediaItemIndex= */
1, /* positionMs= */
5000).waitForTimelineChanged(/* expectedTimeline= */
null, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
currentPlaybackPositions[0] = player.getCurrentPosition();
windowCounts[0] = player.getCurrentTimeline().getWindowCount();
}
}).build();
ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(delegatingMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
assertArrayEquals(new long[] { 2 }, windowCounts);
assertArrayEquals(new int[] { seekToMediaItemIndex }, currentMediaItemIndices);
assertArrayEquals(new long[] { 5_000 }, currentPlaybackPositions);
}
use of com.google.android.exoplayer2.testutil.ExoPlayerTestRunner in project ExoPlayer by google.
the class ExoPlayerTest method modifyPlaylistUnprepared_remainsInIdle_needsPrepareForBuffering.
@Test
public void modifyPlaylistUnprepared_remainsInIdle_needsPrepareForBuffering() throws Exception {
int[] playbackStates = new int[4];
int[] timelineWindowCounts = new int[4];
int[] maskingPlaybackState = { C.INDEX_UNSET };
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForTimelineChanged(placeholderTimeline, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED).executeRunnable(new PlaybackStateCollector(/* index= */
0, playbackStates, timelineWindowCounts)).clearMediaItems().executeRunnable(new PlaybackStateCollector(/* index= */
1, playbackStates, timelineWindowCounts)).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
player.setMediaSource(new FakeMediaSource(), /* startPositionMs= */
1000);
maskingPlaybackState[0] = player.getPlaybackState();
}
}).executeRunnable(new PlaybackStateCollector(/* index= */
2, playbackStates, timelineWindowCounts)).addMediaSources(new FakeMediaSource()).executeRunnable(new PlaybackStateCollector(/* index= */
3, playbackStates, timelineWindowCounts)).seek(/* mediaItemIndex= */
1, /* positionMs= */
2000).prepare().waitForPlaybackState(Player.STATE_BUFFERING).waitForPlaybackState(Player.STATE_READY).waitForPlaybackState(Player.STATE_ENDED).build();
ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(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_IDLE, Player.STATE_IDLE }, playbackStates);
assertArrayEquals(new int[] { 1, 0, 1, 2 }, timelineWindowCounts);
exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_BUFFERING, /* first buffering state after prepare */
Player.STATE_READY, Player.STATE_ENDED);
exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* initial setMediaSources */
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* clear */
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* set media items */
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* add media items */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
Timeline expectedSecondPlaceholderTimeline = new FakeTimeline(TimelineWindowDefinition.createPlaceholder(/* tag= */
0), TimelineWindowDefinition.createPlaceholder(/* tag= */
0));
Timeline expectedSecondRealTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
10_000_000), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
10_000_000));
exoPlayerTestRunner.assertTimelinesSame(placeholderTimeline, Timeline.EMPTY, placeholderTimeline, expectedSecondPlaceholderTimeline, expectedSecondRealTimeline);
assertArrayEquals(new int[] { Player.STATE_IDLE }, maskingPlaybackState);
}
use of com.google.android.exoplayer2.testutil.ExoPlayerTestRunner in project ExoPlayer by google.
the class ExoPlayerTest method stop_withReset_doesResetPosition_correctMasking.
@Test
public void stop_withReset_doesResetPosition_correctMasking() throws Exception {
int[] currentMediaItemIndex = { C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET };
long[] currentPosition = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
long[] bufferedPosition = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
long[] totalBufferedDuration = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
final FakeMediaSource mediaSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().seek(/* mediaItemIndex= */
1, /* positionMs= */
1000).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
currentMediaItemIndex[0] = player.getCurrentMediaItemIndex();
currentPosition[0] = player.getCurrentPosition();
bufferedPosition[0] = player.getBufferedPosition();
totalBufferedDuration[0] = player.getTotalBufferedDuration();
player.stop(/* reset= */
true);
currentMediaItemIndex[1] = player.getCurrentMediaItemIndex();
currentPosition[1] = player.getCurrentPosition();
bufferedPosition[1] = player.getBufferedPosition();
totalBufferedDuration[1] = player.getTotalBufferedDuration();
}
}).waitForPlaybackState(Player.STATE_IDLE).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
currentMediaItemIndex[2] = player.getCurrentMediaItemIndex();
currentPosition[2] = player.getCurrentPosition();
bufferedPosition[2] = player.getBufferedPosition();
totalBufferedDuration[2] = player.getTotalBufferedDuration();
}
}).build();
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource, mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS);
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
testRunner.assertPositionDiscontinuityReasonsEqual(Player.DISCONTINUITY_REASON_SEEK, Player.DISCONTINUITY_REASON_REMOVE);
assertThat(currentMediaItemIndex[0]).isEqualTo(1);
assertThat(currentPosition[0]).isGreaterThan(0);
assertThat(bufferedPosition[0]).isEqualTo(10000);
assertThat(totalBufferedDuration[0]).isEqualTo(10000 - currentPosition[0]);
assertThat(currentMediaItemIndex[1]).isEqualTo(0);
assertThat(currentPosition[1]).isEqualTo(0);
assertThat(bufferedPosition[1]).isEqualTo(0);
assertThat(totalBufferedDuration[1]).isEqualTo(0);
assertThat(currentMediaItemIndex[2]).isEqualTo(0);
assertThat(currentPosition[2]).isEqualTo(0);
assertThat(bufferedPosition[2]).isEqualTo(0);
assertThat(totalBufferedDuration[2]).isEqualTo(0);
}
Aggregations