use of com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilPosition in project ExoPlayer by google.
the class PlaybackStatsListenerTest method playerRelease_callsAllPendingCallbacks.
@Test
public void playerRelease_callsAllPendingCallbacks() throws Exception {
PlaybackStatsListener.Callback callback = mock(PlaybackStatsListener.Callback.class);
PlaybackStatsListener playbackStatsListener = new PlaybackStatsListener(/* keepHistory= */
true, callback);
player.addAnalyticsListener(playbackStatsListener);
MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(/* windowCount= */
1));
player.setMediaSources(ImmutableList.of(mediaSource, mediaSource));
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
// Play close to the end of the first item to ensure the second session is already created, but
// the first one isn't finished yet.
TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */
0, /* positionMs= */
player.getDuration());
runUntilPendingCommandsAreFullyHandled(player);
player.release();
ShadowLooper.idleMainLooper();
ArgumentCaptor<AnalyticsListener.EventTime> eventTimeCaptor = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
verify(callback, times(2)).onPlaybackStatsReady(eventTimeCaptor.capture(), any());
assertThat(eventTimeCaptor.getAllValues().stream().map(eventTime -> eventTime.windowIndex).collect(Collectors.toList())).containsExactly(0, 1);
}
use of com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilPosition in project ExoPlayer by google.
the class PlaybackStatsListenerTest method playlistClear_callsAllPendingCallbacks.
@Test
public void playlistClear_callsAllPendingCallbacks() throws Exception {
PlaybackStatsListener.Callback callback = mock(PlaybackStatsListener.Callback.class);
PlaybackStatsListener playbackStatsListener = new PlaybackStatsListener(/* keepHistory= */
true, callback);
player.addAnalyticsListener(playbackStatsListener);
MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(/* windowCount= */
1));
player.setMediaSources(ImmutableList.of(mediaSource, mediaSource));
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
// Play close to the end of the first item to ensure the second session is already created, but
// the first one isn't finished yet.
TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */
0, /* positionMs= */
player.getDuration());
runUntilPendingCommandsAreFullyHandled(player);
player.clearMediaItems();
ShadowLooper.idleMainLooper();
ArgumentCaptor<AnalyticsListener.EventTime> eventTimeCaptor = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
verify(callback, times(2)).onPlaybackStatsReady(eventTimeCaptor.capture(), any());
assertThat(eventTimeCaptor.getAllValues().stream().map(eventTime -> eventTime.windowIndex).collect(Collectors.toList())).containsExactly(0, 1);
}
use of com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilPosition in project ExoPlayer by google.
the class ExoPlayerTest method stop_doesNotCallOnPositionDiscontinuity.
@Test
public void stop_doesNotCallOnPositionDiscontinuity() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Player.Listener listener = mock(Player.Listener.class);
player.addListener(listener);
player.setMediaSource(new FakeMediaSource());
player.prepare();
TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
0, /* positionMs= */
5 * C.MILLIS_PER_SECOND);
player.stop();
verify(listener, never()).onPositionDiscontinuity(any(), any(), anyInt());
player.release();
}
use of com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilPosition in project ExoPlayer by google.
the class ExoPlayerTest method seekBack_callsOnPositionDiscontinuity.
@Test
public void seekBack_callsOnPositionDiscontinuity() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Player.Listener listener = mock(Player.Listener.class);
player.addListener(listener);
Timeline fakeTimeline = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
true, /* isDynamic= */
true, /* durationUs= */
Util.msToUs(3 * C.DEFAULT_SEEK_BACK_INCREMENT_MS)));
player.setMediaSource(new FakeMediaSource(fakeTimeline));
player.prepare();
TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
0, /* positionMs= */
2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS);
player.seekBack();
ArgumentCaptor<Player.PositionInfo> oldPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
ArgumentCaptor<Player.PositionInfo> newPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
verify(listener, never()).onPositionDiscontinuity(any(), any(), not(eq(Player.DISCONTINUITY_REASON_SEEK)));
verify(listener).onPositionDiscontinuity(oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_SEEK));
List<Player.PositionInfo> oldPositions = oldPosition.getAllValues();
List<Player.PositionInfo> newPositions = newPosition.getAllValues();
assertThat(oldPositions.get(0).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(0).positionMs).isIn(Range.closed(2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS - 20, 2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS));
assertThat(oldPositions.get(0).contentPositionMs).isIn(Range.closed(2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS - 20, 2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS));
assertThat(newPositions.get(0).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(0).positionMs).isIn(Range.closed(C.DEFAULT_SEEK_BACK_INCREMENT_MS - 20, C.DEFAULT_SEEK_BACK_INCREMENT_MS));
assertThat(newPositions.get(0).contentPositionMs).isIn(Range.closed(C.DEFAULT_SEEK_BACK_INCREMENT_MS - 20, C.DEFAULT_SEEK_BACK_INCREMENT_MS));
player.release();
}
use of com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilPosition in project ExoPlayer by google.
the class ExoPlayerTest method targetLiveOffsetInMedia_afterSeekToDefaultPositionInOtherStream_adjustsLiveOffsetToMediaOffset.
@Test
public void targetLiveOffsetInMedia_afterSeekToDefaultPositionInOtherStream_adjustsLiveOffsetToMediaOffset() 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 liveTimeline1 = 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()));
Timeline liveTimeline2 = 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(4_000).build()).build()));
player.pause();
player.addMediaSource(new FakeMediaSource(liveTimeline1));
player.addMediaSource(new FakeMediaSource(liveTimeline2));
// Ensure we override the target live offset to a seek position in the first live stream.
player.seekTo(10_000);
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
// Seek to default position in second stream.
player.seekToNextMediaItem();
// Play until close to the end of the available live window.
TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
1, /* positionMs= */
999_000);
long liveOffsetAtEnd = player.getCurrentLiveOffset();
player.release();
// Assert that player adjusted live offset to the media value.
assertThat(liveOffsetAtEnd).isIn(Range.closed(3_900L, 4_100L));
}
Aggregations