Search in sources :

Example 1 with CastPlayer

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();
}
Also used : ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource)

Example 2 with CastPlayer

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());
}
Also used : Player(com.google.android.exoplayer2.Player) InOrder(org.mockito.InOrder) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 3 with CastPlayer

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());
}
Also used : InOrder(org.mockito.InOrder) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 4 with CastPlayer

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());
}
Also used : Player(com.google.android.exoplayer2.Player) InOrder(org.mockito.InOrder) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 5 with CastPlayer

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());
}
Also used : Player(com.google.android.exoplayer2.Player) InOrder(org.mockito.InOrder) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Aggregations

MediaItem (com.google.android.exoplayer2.MediaItem)10 Test (org.junit.Test)10 Player (com.google.android.exoplayer2.Player)9 InOrder (org.mockito.InOrder)9 CastPlayer (com.google.android.exoplayer2.ext.cast.CastPlayer)2 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)1 ExtractorsFactory (com.google.android.exoplayer2.extractor.ExtractorsFactory)1 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)1 ExtractorMediaSource (com.google.android.exoplayer2.source.ExtractorMediaSource)1 MediaSource (com.google.android.exoplayer2.source.MediaSource)1 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)1 DataSource (com.google.android.exoplayer2.upstream.DataSource)1 DefaultDataSourceFactory (com.google.android.exoplayer2.upstream.DefaultDataSourceFactory)1 DefaultHttpDataSource (com.google.android.exoplayer2.upstream.DefaultHttpDataSource)1 DefaultHttpDataSourceFactory (com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory)1