Search in sources :

Example 21 with MediaItem

use of androidx.media3.common.MediaItem in project media by androidx.

the class CastPlayerTest method removeCurrentMediaItem_notifiesMediaItemTransition.

@Test
public void removeCurrentMediaItem_notifiesMediaItemTransition() {
    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= */
    0);
    // Update with the new timeline after removal.
    updateTimeLine(ImmutableList.of(mediaItem2), /* mediaQueueItemIds= */
    new int[] { 2 }, /* currentItemId= */
    2);
    InOrder inOrder = Mockito.inOrder(mockListener);
    inOrder.verify(mockListener, times(2)).onMediaItemTransition(mediaItemCaptor.capture(), eq(Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockListener, never()).onMediaItemTransition(any(), anyInt());
    assertThat(mediaItemCaptor.getAllValues().get(0).localConfiguration.tag).isEqualTo(mediaItem1.localConfiguration.tag);
    assertThat(mediaItemCaptor.getAllValues().get(1).localConfiguration.tag).isEqualTo(mediaItem2.localConfiguration.tag);
}
Also used : InOrder(org.mockito.InOrder) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 22 with MediaItem

use of androidx.media3.common.MediaItem in project media by androidx.

the class CastPlayerTest method removeMediaItem_atTheStart_notifiesAvailableCommandsChanged.

@Test
public void removeMediaItem_atTheStart_notifiesAvailableCommandsChanged() {
    when(mockRemoteMediaClient.queueJumpToItem(anyInt(), anyLong(), eq(null))).thenReturn(mockPendingResult);
    Player.Commands defaultCommands = createWithDefaultCommands();
    Player.Commands commandsWithSeekToPreviousWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM);
    Player.Commands emptyTimelineCommands = createWithDefaultCommands(/* isTimelineEmpty= */
    true);
    MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
    1);
    MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
    2);
    MediaItem mediaItem3 = createMediaItem(/* mediaQueueItemId= */
    3);
    castPlayer.addMediaItems(ImmutableList.of(mediaItem1, mediaItem2, mediaItem3));
    updateTimeLine(ImmutableList.of(mediaItem1, mediaItem2, mediaItem3), /* mediaQueueItemIds= */
    new int[] { 1, 2, 3 }, /* currentItemId= */
    3);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    castPlayer.removeMediaItem(/* index= */
    0);
    updateTimeLine(ImmutableList.of(mediaItem2, mediaItem3), /* mediaQueueItemIds= */
    new int[] { 2, 3 }, /* currentItemId= */
    3);
    verify(mockListener).onAvailableCommandsChanged(any());
    castPlayer.removeMediaItem(/* index= */
    0);
    updateTimeLine(ImmutableList.of(mediaItem3), /* mediaQueueItemIds= */
    new int[] { 3 }, /* currentItemId= */
    3);
    verify(mockListener).onAvailableCommandsChanged(defaultCommands);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    castPlayer.removeMediaItem(/* index= */
    0);
    updateTimeLine(ImmutableList.of(), /* mediaQueueItemIds= */
    new int[0], /* currentItemId= */
    C.INDEX_UNSET);
    verify(mockListener).onAvailableCommandsChanged(emptyTimelineCommands);
    verify(mockListener, times(3)).onAvailableCommandsChanged(any());
}
Also used : Player(androidx.media3.common.Player) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 23 with MediaItem

use of androidx.media3.common.MediaItem in project media by androidx.

the class CastPlayerTest method addMediaItem_atTheStart_notifiesAvailableCommandsChanged.

@Test
public void addMediaItem_atTheStart_notifiesAvailableCommandsChanged() {
    Player.Commands defaultCommands = createWithDefaultCommands();
    Player.Commands commandsWithSeekToPreviousWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM);
    MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
    1);
    MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
    2);
    MediaItem mediaItem3 = createMediaItem(/* mediaQueueItemId= */
    3);
    castPlayer.addMediaItem(mediaItem1);
    updateTimeLine(ImmutableList.of(mediaItem1), /* mediaQueueItemIds= */
    new int[] { 1 }, /* currentItemId= */
    1);
    verify(mockListener).onAvailableCommandsChanged(defaultCommands);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    castPlayer.addMediaItem(/* index= */
    0, mediaItem2);
    updateTimeLine(ImmutableList.of(mediaItem2, mediaItem1), /* mediaQueueItemIds= */
    new int[] { 2, 1 }, /* currentItemId= */
    1);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    castPlayer.addMediaItem(/* index= */
    0, mediaItem3);
    updateTimeLine(ImmutableList.of(mediaItem3, mediaItem2, mediaItem1), /* mediaQueueItemIds= */
    new int[] { 3, 2, 1 }, /* currentItemId= */
    1);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
}
Also used : Player(androidx.media3.common.Player) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 24 with MediaItem

use of androidx.media3.common.MediaItem in project media by androidx.

the class DefaultMediaItemConverter method getPlayerConfigJson.

@Nullable
private static JSONObject getPlayerConfigJson(MediaItem mediaItem) throws JSONException {
    if (mediaItem.localConfiguration == null || mediaItem.localConfiguration.drmConfiguration == null) {
        return null;
    }
    MediaItem.DrmConfiguration drmConfiguration = mediaItem.localConfiguration.drmConfiguration;
    String drmScheme;
    if (C.WIDEVINE_UUID.equals(drmConfiguration.scheme)) {
        drmScheme = "widevine";
    } else if (C.PLAYREADY_UUID.equals(drmConfiguration.scheme)) {
        drmScheme = "playready";
    } else {
        return null;
    }
    JSONObject playerConfigJson = new JSONObject();
    playerConfigJson.put("withCredentials", false);
    playerConfigJson.put("protectionSystem", drmScheme);
    if (drmConfiguration.licenseUri != null) {
        playerConfigJson.put("licenseUrl", drmConfiguration.licenseUri);
    }
    if (!drmConfiguration.licenseRequestHeaders.isEmpty()) {
        playerConfigJson.put("headers", new JSONObject(drmConfiguration.licenseRequestHeaders));
    }
    return playerConfigJson;
}
Also used : JSONObject(org.json.JSONObject) MediaItem(androidx.media3.common.MediaItem) Nullable(androidx.annotation.Nullable)

Example 25 with MediaItem

use of androidx.media3.common.MediaItem 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)281 Test (org.junit.Test)255 LargeTest (androidx.test.filters.LargeTest)76 CountDownLatch (java.util.concurrent.CountDownLatch)72 Timeline (androidx.media3.common.Timeline)68 Player (androidx.media3.common.Player)57 Nullable (androidx.annotation.Nullable)53 ArrayList (java.util.ArrayList)52 AtomicReference (java.util.concurrent.atomic.AtomicReference)46 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)45 Bundle (android.os.Bundle)36 MediumTest (androidx.test.filters.MediumTest)31 MediaSource (androidx.media3.exoplayer.source.MediaSource)27 MediaMetadata (androidx.media3.common.MediaMetadata)26 PositionInfo (androidx.media3.common.Player.PositionInfo)25 QueueItem (android.support.v4.media.session.MediaSessionCompat.QueueItem)23 MediaItem (androidx.media2.common.MediaItem)23 SmallTest (androidx.test.filters.SmallTest)23 InOrder (org.mockito.InOrder)20 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)19