Search in sources :

Example 11 with CastPlayer

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

Example 12 with CastPlayer

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

Example 13 with CastPlayer

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();
    }
}
Also used : CastPlayer(com.google.android.exoplayer2.ext.cast.CastPlayer) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector)

Example 14 with CastPlayer

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);
}
Also used : AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener)

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 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)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