Search in sources :

Example 96 with MediaItem

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

the class MediaBrowserServiceCompatCallbackWithMediaBrowserTest method onLoadItemCalledByGetItem_browsable.

@Test
public void onLoadItemCalledByGetItem_browsable() throws Exception {
    String testMediaId = "test_media_item";
    MediaBrowserCompat.MediaItem testItem = createBrowserMediaItem(testMediaId, /* browsable= */
    true, /* playable= */
    false);
    CountDownLatch latch = new CountDownLatch(1);
    MockMediaBrowserServiceCompat.setMediaBrowserServiceProxy(new Proxy() {

        @Override
        public void onLoadItem(String itemId, Result<MediaBrowserCompat.MediaItem> result) {
            if (testMediaId.equals(itemId)) {
                result.sendResult(testItem);
                latch.countDown();
            }
        }
    });
    RemoteMediaBrowser browser = new RemoteMediaBrowser(context, token, /* waitForConnection= */
    true, /* connectionHints= */
    null);
    LibraryResult<MediaItem> result = browser.getItem(testMediaId);
    assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
    assertThat(result.resultCode).isEqualTo(LibraryResult.RESULT_SUCCESS);
    assertItemEquals(testItem, result.value);
    assertThat(result.value.mediaMetadata.folderType).isEqualTo(MediaMetadata.FOLDER_TYPE_MIXED);
}
Also used : MediaBrowserCompat(android.support.v4.media.MediaBrowserCompat) Proxy(androidx.media3.session.MockMediaBrowserServiceCompat.Proxy) MediaItem(androidx.media3.common.MediaItem) CountDownLatch(java.util.concurrent.CountDownLatch) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 97 with MediaItem

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

the class MediaBrowserServiceCompatCallbackWithMediaBrowserTest method onLoadChildrenWithOptionsCalledByGetChildrenWithoutOptions_nullResult.

@Test
public void onLoadChildrenWithOptionsCalledByGetChildrenWithoutOptions_nullResult() throws Exception {
    String testParentId = "test_media_parent";
    int testPage = 2;
    int testPageSize = 4;
    CountDownLatch latch = new CountDownLatch(1);
    MockMediaBrowserServiceCompat.setMediaBrowserServiceProxy(new Proxy() {

        @Override
        public void onLoadChildren(String parentId, Result<List<MediaBrowserCompat.MediaItem>> result, Bundle options) {
            assertThat(parentId).isEqualTo(testParentId);
            assertThat(options.getInt(MediaBrowserCompat.EXTRA_PAGE)).isEqualTo(testPage);
            assertThat(options.getInt(MediaBrowserCompat.EXTRA_PAGE_SIZE)).isEqualTo(testPageSize);
            result.sendResult(null);
            latch.countDown();
        }
    });
    RemoteMediaBrowser browser = new RemoteMediaBrowser(context, token, true, null);
    LibraryResult<ImmutableList<MediaItem>> result = browser.getChildren(testParentId, testPage, testPageSize, null);
    assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
    assertThat(result.resultCode).isNotEqualTo(LibraryResult.RESULT_SUCCESS);
    assertThat(result.params).isNull();
}
Also used : MediaBrowserCompat(android.support.v4.media.MediaBrowserCompat) Proxy(androidx.media3.session.MockMediaBrowserServiceCompat.Proxy) Bundle(android.os.Bundle) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 98 with MediaItem

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

the class MediaBrowserServiceCompatCallbackWithMediaBrowserTest method onLoadChildrenWithOptionsCalledByGetChildrenWithOptions.

@Test
public void onLoadChildrenWithOptionsCalledByGetChildrenWithOptions() throws Exception {
    String testParentId = "test_media_parent";
    int testPage = 2;
    int testPageSize = 4;
    LibraryParams testParams = MediaTestUtils.createLibraryParams();
    List<MediaBrowserCompat.MediaItem> testMediaItemList = createBrowserMediaItems(testPageSize / 2);
    CountDownLatch latch = new CountDownLatch(1);
    MockMediaBrowserServiceCompat.setMediaBrowserServiceProxy(new Proxy() {

        @Override
        public void onLoadChildren(String parentId, Result<List<MediaBrowserCompat.MediaItem>> result, Bundle options) {
            assertThat(parentId).isEqualTo(testParentId);
            assertThat(options.getInt(MediaBrowserCompat.EXTRA_PAGE)).isEqualTo(testPage);
            assertThat(options.getInt(MediaBrowserCompat.EXTRA_PAGE_SIZE)).isEqualTo(testPageSize);
            assertThat(TestUtils.contains(options, testParams.extras)).isTrue();
            result.sendResult(testMediaItemList);
            latch.countDown();
        }
    });
    RemoteMediaBrowser browser = new RemoteMediaBrowser(context, token, true, null);
    LibraryResult<ImmutableList<MediaItem>> result = browser.getChildren(testParentId, testPage, testPageSize, testParams);
    assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
    assertThat(result.resultCode).isEqualTo(LibraryResult.RESULT_SUCCESS);
    assertItemsEquals(testMediaItemList, result.value);
    assertThat(result.params).isNull();
}
Also used : Bundle(android.os.Bundle) ImmutableList(com.google.common.collect.ImmutableList) CountDownLatch(java.util.concurrent.CountDownLatch) MediaBrowserCompat(android.support.v4.media.MediaBrowserCompat) Proxy(androidx.media3.session.MockMediaBrowserServiceCompat.Proxy) MediaItem(androidx.media3.common.MediaItem) LibraryParams(androidx.media3.session.MediaLibraryService.LibraryParams) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 99 with MediaItem

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

the class MediaControllerStateMaskingTest method seekToPreviousMediaItem.

@Test
public void seekToPreviousMediaItem() throws Exception {
    int initialMediaItemIndex = 1;
    String firstMediaId = "firstMediaId";
    String secondMediaId = "secondMediaId";
    String thirdMediaId = "thirdMediaId";
    String testCurrentMediaId = firstMediaId;
    int testMediaItemIndex = 0;
    Bundle playerConfig = new RemoteMediaSession.MockPlayerConfigBuilder().setTimeline(MediaTestUtils.createTimeline(MediaTestUtils.createMediaItems(firstMediaId, secondMediaId, thirdMediaId))).setCurrentMediaItemIndex(initialMediaItemIndex).setCurrentPeriodIndex(initialMediaItemIndex).build();
    remoteSession.setPlayer(playerConfig);
    MediaController controller = controllerTestRule.createController(remoteSession.getToken());
    CountDownLatch latch = new CountDownLatch(3);
    AtomicReference<MediaItem> newMediaItemRef = new AtomicReference<>();
    AtomicReference<PositionInfo> oldPositionInfoRef = new AtomicReference<>();
    AtomicReference<PositionInfo> newPositionInfoRef = new AtomicReference<>();
    AtomicReference<Player.Events> onEventsRef = new AtomicReference<>();
    Player.Listener listener = new Player.Listener() {

        @Override
        public void onMediaItemTransition(@Nullable MediaItem mediaItem, int reason) {
            newMediaItemRef.set(mediaItem);
            latch.countDown();
        }

        @Override
        public void onPositionDiscontinuity(PositionInfo oldPosition, PositionInfo newPosition, int reason) {
            oldPositionInfoRef.set(oldPosition);
            newPositionInfoRef.set(newPosition);
            latch.countDown();
        }

        @Override
        public void onEvents(Player player, Player.Events events) {
            onEventsRef.set(events);
            latch.countDown();
        }
    };
    threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
    AtomicInteger currentMediaItemIndexRef = new AtomicInteger();
    threadTestRule.getHandler().postAndSync(() -> {
        controller.seekToPreviousMediaItem();
        currentMediaItemIndexRef.set(controller.getCurrentMediaItemIndex());
    });
    assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
    assertThat(newMediaItemRef.get().mediaId).isEqualTo(testCurrentMediaId);
    assertThat(oldPositionInfoRef.get().mediaItemIndex).isEqualTo(initialMediaItemIndex);
    assertThat(newPositionInfoRef.get().mediaItemIndex).isEqualTo(testMediaItemIndex);
    assertThat(onEventsRef.get().contains(Player.EVENT_MEDIA_ITEM_TRANSITION)).isTrue();
    assertThat(onEventsRef.get().contains(Player.EVENT_POSITION_DISCONTINUITY)).isTrue();
    assertThat(currentMediaItemIndexRef.get()).isEqualTo(testMediaItemIndex);
}
Also used : Player(androidx.media3.common.Player) Bundle(android.os.Bundle) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MediaItem(androidx.media3.common.MediaItem) PositionInfo(androidx.media3.common.Player.PositionInfo) Nullable(androidx.annotation.Nullable) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 100 with MediaItem

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

the class MediaControllerStateMaskingTest method seekTo_withEmptyTimeline_doesNotCallOnMediaItemTransition.

@Test
public void seekTo_withEmptyTimeline_doesNotCallOnMediaItemTransition() throws Exception {
    long testPosition = 16_000;
    Bundle playerConfig = new RemoteMediaSession.MockPlayerConfigBuilder().setTimeline(Timeline.EMPTY).build();
    remoteSession.setPlayer(playerConfig);
    MediaController controller = controllerTestRule.createController(remoteSession.getToken());
    CountDownLatch latch = new CountDownLatch(1);
    Player.Listener listener = new Player.Listener() {

        @Override
        public void onMediaItemTransition(@Nullable MediaItem mediaItem, int reason) {
            latch.countDown();
        }
    };
    threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
    threadTestRule.getHandler().postAndSync(() -> controller.seekTo(testPosition));
    assertThat(latch.await(NO_RESPONSE_TIMEOUT_MS, MILLISECONDS)).isFalse();
}
Also used : Player(androidx.media3.common.Player) Bundle(android.os.Bundle) MediaItem(androidx.media3.common.MediaItem) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(androidx.annotation.Nullable) LargeTest(androidx.test.filters.LargeTest) 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