use of com.google.android.exoplayer2.ExoPlayer in project ExoPlayer by google.
the class ExoPlayerTest method seekTo_cancelsSourceDiscontinuity_callsOnPositionDiscontinuity.
@Test
public void seekTo_cancelsSourceDiscontinuity_callsOnPositionDiscontinuity() throws Exception {
Timeline timeline1 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
2));
final Timeline timeline2 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
3));
final FakeMediaSource mediaSource = new FakeMediaSource(timeline1, ExoPlayerTestRunner.VIDEO_FORMAT);
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Player.Listener listener = mock(Player.Listener.class);
player.addListener(listener);
player.setMediaSource(mediaSource);
player.prepare();
TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
1, /* positionMs= */
2000);
player.seekTo(/* mediaItemIndex= */
1, /* positionMs= */
2122);
// This causes a DISCONTINUITY_REASON_REMOVE between pending operations that needs to be
// cancelled by the seek below.
mediaSource.setNewSourceInfo(timeline2);
player.play();
player.seekTo(/* mediaItemIndex= */
0, /* positionMs= */
2222);
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
ArgumentCaptor<Player.PositionInfo> oldPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
ArgumentCaptor<Player.PositionInfo> newPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
InOrder inOrder = inOrder(listener);
inOrder.verify(listener).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
inOrder.verify(listener, times(2)).onPositionDiscontinuity(oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_SEEK));
inOrder.verify(listener).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
inOrder.verify(listener, never()).onPositionDiscontinuity(any(), any(), anyInt());
List<Player.PositionInfo> oldPositions = oldPosition.getAllValues();
List<Player.PositionInfo> newPositions = newPosition.getAllValues();
// First seek
assertThat(oldPositions.get(0).mediaItemIndex).isEqualTo(1);
assertThat(oldPositions.get(0).positionMs).isIn(Range.closed(1980L, 2000L));
assertThat(oldPositions.get(0).contentPositionMs).isIn(Range.closed(1980L, 2000L));
assertThat(newPositions.get(0).mediaItemIndex).isEqualTo(1);
assertThat(newPositions.get(0).positionMs).isEqualTo(2122);
assertThat(newPositions.get(0).contentPositionMs).isEqualTo(2122);
// Second seek.
assertThat(oldPositions.get(1).mediaItemIndex).isEqualTo(1);
assertThat(oldPositions.get(1).positionMs).isEqualTo(2122);
assertThat(oldPositions.get(1).contentPositionMs).isEqualTo(2122);
assertThat(newPositions.get(1).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(1).positionMs).isEqualTo(2222);
assertThat(newPositions.get(1).contentPositionMs).isEqualTo(2222);
player.release();
}
use of com.google.android.exoplayer2.ExoPlayer in project ExoPlayer by google.
the class ExoPlayerTest method setMediaItem_withMediaMetadata_updatesMediaMetadata.
@Test
public void setMediaItem_withMediaMetadata_updatesMediaMetadata() {
MediaMetadata mediaMetadata = new MediaMetadata.Builder().setTitle("the title").build();
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.setMediaItem(new MediaItem.Builder().setMediaId("id").setUri(Uri.EMPTY).setMediaMetadata(mediaMetadata).build());
assertThat(player.getMediaMetadata()).isEqualTo(mediaMetadata);
}
use of com.google.android.exoplayer2.ExoPlayer in project ExoPlayer by google.
the class ExoPlayerTest method seekTo_whilePlayingAd_doesntBlockFutureUpdates.
// https://github.com/google/ExoPlayer/issues/8349
@Test
public void seekTo_whilePlayingAd_doesntBlockFutureUpdates() throws Exception {
long contentDurationMs = 10_000;
long adDurationMs = 4_000;
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
new Object(), /* adGroupTimesUs...= */
0).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1).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);
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.setMediaSource(adsMediaSource);
player.pause();
player.prepare();
runUntilPlaybackState(player, Player.STATE_READY);
player.seekTo(0, 8000);
player.play();
// This times out if playback info updates after the seek are blocked.
runUntilPlaybackState(player, Player.STATE_ENDED);
}
use of com.google.android.exoplayer2.ExoPlayer in project ExoPlayer by google.
the class ExoPlayerTest method repeatModeChanges.
@Test
public void repeatModeChanges() throws Exception {
Timeline timeline = new FakeTimeline(/* windowCount= */
3);
FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
AnalyticsListener mockAnalyticsListener = mock(AnalyticsListener.class);
player.addAnalyticsListener(mockAnalyticsListener);
player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
player.prepare();
runUntilTimelineChanged(player);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
1);
player.setRepeatMode(Player.REPEAT_MODE_ONE);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
1);
player.setRepeatMode(Player.REPEAT_MODE_OFF);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
2);
player.setRepeatMode(Player.REPEAT_MODE_ONE);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
2);
player.setRepeatMode(Player.REPEAT_MODE_ALL);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
0);
player.setRepeatMode(Player.REPEAT_MODE_ONE);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
0);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
0);
player.setRepeatMode(Player.REPEAT_MODE_OFF);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
1);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
2);
player.play();
runUntilPlaybackState(player, Player.STATE_ENDED);
ArgumentCaptor<AnalyticsListener.EventTime> eventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
verify(mockAnalyticsListener, times(10)).onMediaItemTransition(eventTimes.capture(), any(), anyInt());
assertThat(eventTimes.getAllValues().stream().map(eventTime -> eventTime.currentWindowIndex).collect(Collectors.toList())).containsExactly(0, 1, 1, 2, 2, 0, 0, 0, 1, 2).inOrder();
assertThat(renderer.isEnded).isTrue();
}
use of com.google.android.exoplayer2.ExoPlayer in project ExoPlayer by google.
the class ExoPlayerTest method setShuffleModeEnabled_notifiesAvailableCommandsChanged.
@Test
public void setShuffleModeEnabled_notifiesAvailableCommandsChanged() {
Player.Commands commandsWithSeekToPreviousWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM);
Player.Commands commandsWithSeekToNextWindow = createWithDefaultCommands(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT);
Player.Listener mockListener = mock(Player.Listener.class);
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.addListener(mockListener);
MediaSource mediaSource = new ConcatenatingMediaSource(false, new FakeShuffleOrder(/* length= */
2), new FakeMediaSource(), new FakeMediaSource());
player.addMediaSource(mediaSource);
verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToNextWindow);
// Check that there were no other calls to onAvailableCommandsChanged.
verify(mockListener).onAvailableCommandsChanged(any());
player.setShuffleModeEnabled(true);
verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow);
verify(mockListener, times(2)).onAvailableCommandsChanged(any());
}
Aggregations