use of com.google.android.exoplayer2.ext.cast.CastPlayer in project ExoPlayer by google.
the class CastPlayerTest method removeCurrentMediaItem_notifiesPositionDiscontinuity.
@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void removeCurrentMediaItem_notifiesPositionDiscontinuity() {
MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
1);
MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
2);
List<MediaItem> mediaItems = ImmutableList.of(mediaItem1, mediaItem2);
int[] mediaQueueItemIds = new int[] { 1, 2 };
castPlayer.addMediaItems(mediaItems);
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
1, new int[] { MediaInfo.STREAM_TYPE_BUFFERED, MediaInfo.STREAM_TYPE_BUFFERED }, /* durationsMs= */
new long[] { 20_000L, 30_000L }, /* positionMs= */
1234);
castPlayer.removeMediaItem(/* index= */
0);
// Update with the new timeline after removal.
updateTimeLine(ImmutableList.of(mediaItem2), /* mediaQueueItemIds= */
new int[] { 2 }, /* currentItemId= */
2, new int[] { MediaInfo.STREAM_TYPE_BUFFERED }, /* durationsMs= */
new long[] { 20_000L }, /* positionMs= */
0);
Player.PositionInfo oldPosition = new Player.PositionInfo(/* windowUid= */
1, /* windowIndex= */
0, new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build(), /* periodUid= */
1, /* periodIndex= */
0, /* positionMs= */
1234, /* contentPositionMs= */
1234, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
Player.PositionInfo newPosition = new Player.PositionInfo(/* windowUid= */
2, /* windowIndex= */
0, new MediaItem.Builder().setUri(Uri.EMPTY).setTag(2).build(), /* periodUid= */
2, /* periodIndex= */
0, /* positionMs= */
0, /* contentPositionMs= */
0, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
InOrder inOrder = Mockito.inOrder(mockListener);
inOrder.verify(mockListener).onPositionDiscontinuity(eq(Player.DISCONTINUITY_REASON_REMOVE));
inOrder.verify(mockListener).onPositionDiscontinuity(eq(oldPosition), eq(newPosition), eq(Player.DISCONTINUITY_REASON_REMOVE));
inOrder.verify(mockListener, never()).onPositionDiscontinuity(anyInt());
inOrder.verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
}
use of com.google.android.exoplayer2.ext.cast.CastPlayer in project ExoPlayer by google.
the class CastPlayerTest method removeNonCurrentMediaItem_doesNotNotifyPositionDiscontinuity.
@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void removeNonCurrentMediaItem_doesNotNotifyPositionDiscontinuity() {
MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
1);
MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
2);
List<MediaItem> mediaItems = ImmutableList.of(mediaItem1, mediaItem2);
int[] mediaQueueItemIds = new int[] { 1, 2 };
castPlayer.addMediaItems(mediaItems);
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
1);
castPlayer.removeMediaItem(/* index= */
1);
updateTimeLine(ImmutableList.of(mediaItem1), /* mediaQueueItemIds= */
new int[] { 1 }, /* currentItemId= */
1);
verify(mockListener, never()).onPositionDiscontinuity(anyInt());
verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
}
use of com.google.android.exoplayer2.ext.cast.CastPlayer in project zype-android by zype.
the class PlayerFragment method initPlayer.
// Player
private void initPlayer() {
Logger.d("initPlayer()");
if (currentPlayer == null) {
trackSelector = new DefaultTrackSelector();
PlayerEventListener playerEventListener = new PlayerEventListener();
PlayerEventListener castPlayerEventListener = new PlayerEventListener();
player = ExoPlayerFactory.newSimpleInstance(getActivity(), trackSelector);
player.addListener(playerEventListener);
playerView.setPlayer(player);
playerView.setControlDispatcher(new PlayerControlDispatcher());
castPlayer = new CastPlayer(castContext);
castPlayer.addListener(playerEventListener);
castPlayer.setSessionAvailabilityListener(new CastSessionAvailabilityListener());
castControlView.setPlayer(castPlayer);
}
if (isPlayerControlsEnabled()) {
play();
} else {
pause();
}
}
use of com.google.android.exoplayer2.ext.cast.CastPlayer in project HybridMediaPlayer by mkaflowski.
the class ExoMediaPlayer method prepare.
@Override
public void prepare() {
exoPlayer.addAnalyticsListener(new AnalyticsListener() {
@Override
public void onAudioSessionIdChanged(EventTime eventTime, int audioSessionId) {
setEqualizer();
if (onAudioSessionIdSetListener != null)
onAudioSessionIdSetListener.onAudioSessionIdset(audioSessionId);
}
});
isPreparing = true;
exoPlayer.prepare(exoMediaSource);
shouldBeWindow = initialWindowNum;
currentWindow = initialWindowNum;
if (initialWindowNum != 0)
exoPlayer.seekTo(initialWindowNum, 0);
if (!isCasting)
init();
if (castPlayer != null && isCasting()) {
castPlayer.loadItems(mediaItems, initialWindowNum, 0, Player.REPEAT_MODE_OFF);
// castPlayer.setPlayWhenReady(true);
}
if (onTrackChangedListener != null)
onTrackChangedListener.onTrackChanged(false);
}
Aggregations