Search in sources :

Example 1 with CastPlayer

use of androidx.media3.cast.CastPlayer in project media by androidx.

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(androidx.media3.common.Player) InOrder(org.mockito.InOrder) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 2 with CastPlayer

use of androidx.media3.cast.CastPlayer in project media by androidx.

the class CastPlayerTest method removeCurrentMediaItem_byRemoteClient_notifiesPositionDiscontinuity.

@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void removeCurrentMediaItem_byRemoteClient_notifiesPositionDiscontinuity() {
    MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
    1);
    MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
    2);
    List<MediaItem> mediaItems = ImmutableList.of(mediaItem1, mediaItem2);
    castPlayer.addMediaItems(mediaItems);
    updateTimeLine(mediaItems, new int[] { 1, 2 }, /* currentItemId= */
    1, new int[] { MediaInfo.STREAM_TYPE_BUFFERED, MediaInfo.STREAM_TYPE_BUFFERED }, /* durationsMs= */
    new long[] { 20_000L, 30_000L }, /* positionMs= */
    1234);
    // Update with the new timeline after removal on the device.
    updateTimeLine(ImmutableList.of(mediaItem2), /* mediaQueueItemIds= */
    new int[] { 2 }, /* currentItemId= */
    2, new int[] { MediaInfo.STREAM_TYPE_BUFFERED }, /* durationsMs= */
    new long[] { 30_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, // position at which we receive the timeline change
    0, // position at which we receive the timeline change
    0, /* 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(androidx.media3.common.Player) InOrder(org.mockito.InOrder) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 3 with CastPlayer

use of androidx.media3.cast.CastPlayer in project media by androidx.

the class CastPlayerTest method autoTransition_notifiesPositionDiscontinuity.

@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void autoTransition_notifiesPositionDiscontinuity() {
    int[] mediaQueueItemIds = new int[] { 1, 2 };
    int[] streamTypes = { MediaInfo.STREAM_TYPE_BUFFERED, MediaInfo.STREAM_TYPE_BUFFERED };
    long[] durationsFirstMs = { 12500, C.TIME_UNSET };
    // When the remote Cast player transitions to an item that wasn't played before, the media state
    // delivers the duration for that media item which updates the timeline accordingly.
    long[] durationsSecondMs = { 12500, 22000 };
    List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
    castPlayer.addMediaItems(mediaItems);
    updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
    1, /* streamTypes= */
    streamTypes, /* durationsMs= */
    durationsFirstMs, /* positionMs= */
    C.TIME_UNSET);
    updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
    2, /* streamTypes= */
    streamTypes, /* durationsMs= */
    durationsSecondMs, /* positionMs= */
    C.TIME_UNSET);
    Player.PositionInfo oldPosition = new Player.PositionInfo(/* windowUid= */
    1, /* windowIndex= */
    0, new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build(), /* periodUid= */
    1, /* periodIndex= */
    0, /* positionMs= */
    12500, /* contentPositionMs= */
    12500, /* adGroupIndex= */
    C.INDEX_UNSET, /* adIndexInAdGroup= */
    C.INDEX_UNSET);
    Player.PositionInfo newPosition = new Player.PositionInfo(/* windowUid= */
    2, /* windowIndex= */
    1, new MediaItem.Builder().setUri(Uri.EMPTY).setTag(2).build(), /* periodUid= */
    2, /* periodIndex= */
    1, /* 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_AUTO_TRANSITION));
    inOrder.verify(mockListener).onPositionDiscontinuity(eq(oldPosition), eq(newPosition), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(anyInt());
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
}
Also used : Player(androidx.media3.common.Player) InOrder(org.mockito.InOrder) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 4 with CastPlayer

use of androidx.media3.cast.CastPlayer in project media by androidx.

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(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 5 with CastPlayer

use of androidx.media3.cast.CastPlayer in project media by androidx.

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(androidx.media3.common.Player) InOrder(org.mockito.InOrder) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Aggregations

MediaItem (androidx.media3.common.MediaItem)10 Test (org.junit.Test)10 Player (androidx.media3.common.Player)9 InOrder (org.mockito.InOrder)9 CastPlayer (androidx.media3.cast.CastPlayer)1 ExoPlayer (androidx.media3.exoplayer.ExoPlayer)1