use of androidx.media3.test.utils.FakeTimeline in project media by androidx.
the class ExoPlayerTest method release_correctMasking.
@Test
public void release_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.release();
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();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource, mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS);
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(1);
assertThat(currentPosition[1]).isEqualTo(currentPosition[0]);
assertThat(bufferedPosition[1]).isEqualTo(1000);
assertThat(totalBufferedDuration[1]).isEqualTo(0);
assertThat(currentMediaItemIndex[2]).isEqualTo(1);
assertThat(currentPosition[2]).isEqualTo(currentPosition[0]);
assertThat(bufferedPosition[2]).isEqualTo(1000);
assertThat(totalBufferedDuration[2]).isEqualTo(0);
}
use of androidx.media3.test.utils.FakeTimeline in project media by androidx.
the class ExoPlayerTest method clearMediaItems.
@Test
public void clearMediaItems() throws Exception {
Timeline timeline = new FakeTimeline();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForTimelineChanged(timeline, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).waitForPlaybackState(Player.STATE_READY).clearMediaItems().waitForPlaybackState(Player.STATE_ENDED).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, Timeline.EMPTY);
exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* media item set (masked timeline) */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, /* source prepared */
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
}
use of androidx.media3.test.utils.FakeTimeline in project media by androidx.
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 androidx.media3.test.utils.FakeTimeline in project media by androidx.
the class ExoPlayerTest method playMultiPeriodTimeline.
/**
* Tests playback of a source that exposes three periods.
*/
@Test
public void playMultiPeriodTimeline() throws Exception {
Timeline timeline = new FakeTimeline(/* windowCount= */
3);
FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
Player.Listener mockPlayerListener = mock(Player.Listener.class);
player.addListener(mockPlayerListener);
player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
player.prepare();
player.play();
runUntilPlaybackState(player, Player.STATE_ENDED);
InOrder inOrder = Mockito.inOrder(mockPlayerListener);
inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(new FakeMediaSource.InitialTimeline(timeline))), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(timeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
inOrder.verify(mockPlayerListener, times(2)).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
assertThat(renderer.getFormatsRead()).containsExactly(ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.VIDEO_FORMAT);
assertThat(renderer.sampleBufferReadCount).isEqualTo(3);
assertThat(renderer.isEnded).isTrue();
}
use of androidx.media3.test.utils.FakeTimeline in project media by androidx.
the class ExoPlayerTest method targetLiveOffsetInMedia_withUserSeek_adjustsLiveOffsetToSeek.
@Test
public void targetLiveOffsetInMedia_withUserSeek_adjustsLiveOffsetToSeek() throws Exception {
long windowStartUnixTimeMs = 987_654_321_000L;
long nowUnixTimeMs = windowStartUnixTimeMs + 20_000;
ExoPlayer player = new TestExoPlayerBuilder(context).setClock(new FakeClock(/* initialTimeMs= */
nowUnixTimeMs, /* isAutoAdvancing= */
true)).build();
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
1000 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
8 * C.MICROS_PER_SECOND, /* windowOffsetInFirstPeriodUs= */
Util.msToUs(windowStartUnixTimeMs), ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(9_000).build()).build()));
player.pause();
player.setMediaSource(new FakeMediaSource(timeline));
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
long liveOffsetAtStart = player.getCurrentLiveOffset();
// Verify test setup (now = 20 seconds in live window, default start position = 8 seconds).
assertThat(liveOffsetAtStart).isIn(Range.closed(11_900L, 12_100L));
// Seek to a live offset of 2 seconds.
player.seekTo(18_000);
// Play until close to the end of the available live window.
TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
0, /* positionMs= */
999_000);
long liveOffsetAtEnd = player.getCurrentLiveOffset();
player.release();
// Assert the live offset adjustment was permanent.
assertThat(liveOffsetAtEnd).isIn(Range.closed(1_900L, 2_100L));
}
Aggregations