use of com.google.android.exoplayer2.ext.cast.CastPlayer in project HybridMediaPlayer by mkaflowski.
the class ExoMediaPlayer method setDataSource.
public void setDataSource(List<MediaSourceInfo> normalSources, List<MediaSourceInfo> castSources, CastContext castContext) {
String userAgent = Util.getUserAgent(context, "yourApplicationName");
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent, null, /* listener */
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, null, httpDataSourceFactory);
// Produces Extractor instances for parsing the media data.
ExtractorsFactory extractorsFactory = new SeekableExtractorsFactory();
MediaSource[] sources = new MediaSource[normalSources.size()];
for (int i = 0; i < normalSources.size(); i++) {
// This is the MediaSource representing the media to be played.
sources[i] = new ExtractorMediaSource(Uri.parse(normalSources.get(i).getUrl()), dataSourceFactory, extractorsFactory, null, null);
}
exoMediaSource = new ConcatenatingMediaSource(sources);
setCastMediaSourceInfoList(castSources);
prepare();
if (castContext != null) {
castPlayer = new CastPlayer(castContext);
castPlayer.setSessionAvailabilityListener(this);
castPlayer.addListener(new MyPlayerEventListener(castPlayer));
}
init();
}
use of com.google.android.exoplayer2.ext.cast.CastPlayer in project ExoPlayer by google.
the class CastPlayerTest method seekBack_notifiesPositionDiscontinuity.
@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void seekBack_notifiesPositionDiscontinuity() {
when(mockRemoteMediaClient.seek(anyLong())).thenReturn(mockPendingResult);
int[] mediaQueueItemIds = new int[] { 1 };
List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
int currentItemId = 1;
int[] streamTypes = new int[] { MediaInfo.STREAM_TYPE_BUFFERED };
long[] durationsMs = new long[] { 3 * C.DEFAULT_SEEK_BACK_INCREMENT_MS };
long positionMs = 2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS;
castPlayer.addMediaItems(mediaItems);
updateTimeLine(mediaItems, mediaQueueItemIds, currentItemId, streamTypes, durationsMs, positionMs);
castPlayer.seekBack();
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build();
Player.PositionInfo oldPosition = new Player.PositionInfo(/* windowUid= */
1, /* windowIndex= */
0, mediaItem, /* periodUid= */
1, /* periodIndex= */
0, /* positionMs= */
2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS, /* contentPositionMs= */
2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
Player.PositionInfo newPosition = new Player.PositionInfo(/* windowUid= */
1, /* windowIndex= */
0, mediaItem, /* periodUid= */
1, /* periodIndex= */
0, /* positionMs= */
C.DEFAULT_SEEK_BACK_INCREMENT_MS, /* contentPositionMs= */
C.DEFAULT_SEEK_BACK_INCREMENT_MS, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
InOrder inOrder = Mockito.inOrder(mockListener);
inOrder.verify(mockListener).onPositionDiscontinuity(eq(Player.DISCONTINUITY_REASON_SEEK));
inOrder.verify(mockListener).onPositionDiscontinuity(eq(oldPosition), eq(newPosition), eq(Player.DISCONTINUITY_REASON_SEEK));
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 seekTo_sameWindow_doesNotNotifyMediaItemTransition.
@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void seekTo_sameWindow_doesNotNotifyMediaItemTransition() {
when(mockRemoteMediaClient.seek(anyLong())).thenReturn(mockPendingResult);
int[] mediaQueueItemIds = new int[] { 1, 2 };
List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
castPlayer.addMediaItems(mediaItems);
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
1);
castPlayer.seekTo(/* windowIndex= */
0, /* positionMs= */
1234);
InOrder inOrder = Mockito.inOrder(mockListener);
inOrder.verify(mockListener).onMediaItemTransition(any(), eq(Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED));
inOrder.verify(mockListener, never()).onMediaItemTransition(any(), anyInt());
}
use of com.google.android.exoplayer2.ext.cast.CastPlayer in project ExoPlayer by google.
the class CastPlayerTest method seekForward_notifiesPositionDiscontinuity.
@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void seekForward_notifiesPositionDiscontinuity() {
when(mockRemoteMediaClient.seek(anyLong())).thenReturn(mockPendingResult);
int[] mediaQueueItemIds = new int[] { 1 };
List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
int currentItemId = 1;
int[] streamTypes = new int[] { MediaInfo.STREAM_TYPE_BUFFERED };
long[] durationsMs = new long[] { 2 * C.DEFAULT_SEEK_FORWARD_INCREMENT_MS };
long positionMs = 0;
castPlayer.addMediaItems(mediaItems);
updateTimeLine(mediaItems, mediaQueueItemIds, currentItemId, streamTypes, durationsMs, positionMs);
castPlayer.seekForward();
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build();
Player.PositionInfo oldPosition = new Player.PositionInfo(/* windowUid= */
1, /* windowIndex= */
0, mediaItem, /* periodUid= */
1, /* periodIndex= */
0, /* positionMs= */
0, /* contentPositionMs= */
0, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
Player.PositionInfo newPosition = new Player.PositionInfo(/* windowUid= */
1, /* windowIndex= */
0, mediaItem, /* periodUid= */
1, /* periodIndex= */
0, /* positionMs= */
C.DEFAULT_SEEK_FORWARD_INCREMENT_MS, /* contentPositionMs= */
C.DEFAULT_SEEK_FORWARD_INCREMENT_MS, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
InOrder inOrder = Mockito.inOrder(mockListener);
inOrder.verify(mockListener).onPositionDiscontinuity(eq(Player.DISCONTINUITY_REASON_SEEK));
inOrder.verify(mockListener).onPositionDiscontinuity(eq(oldPosition), eq(newPosition), eq(Player.DISCONTINUITY_REASON_SEEK));
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 clearMediaItems_notifiesPositionDiscontinuity.
@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void clearMediaItems_notifiesPositionDiscontinuity() {
int[] mediaQueueItemIds = new int[] { 1, 2 };
List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
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.clearMediaItems();
updateTimeLine(/* mediaItems= */
ImmutableList.of(), /* mediaQueueItemIds= */
new int[0], /* currentItemId= */
C.INDEX_UNSET, 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= */
null, /* windowIndex= */
0, /* mediaItem= */
null, /* periodUid= */
null, /* 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());
}
Aggregations