Search in sources :

Example 6 with MediaLibrarySession

use of androidx.media3.session.MediaLibraryService.MediaLibrarySession in project media by androidx.

the class MediaBrowserListenerTest method onChildrenChanged_calledWhenSubscribed2.

@Test
public void onChildrenChanged_calledWhenSubscribed2() throws Exception {
    // This test uses MediaLibrarySession.notifyChildrenChanged(ControllerInfo).
    String expectedParentId = SUBSCRIBE_ID_NOTIFY_CHILDREN_CHANGED_TO_ONE;
    CountDownLatch latch = new CountDownLatch(1);
    AtomicReference<String> parentIdRef = new AtomicReference<>();
    AtomicInteger itemCountRef = new AtomicInteger();
    AtomicReference<LibraryParams> paramsRef = new AtomicReference<>();
    MediaBrowser.Listener browserListenerProxy = new MediaBrowser.Listener() {

        @Override
        public void onChildrenChanged(MediaBrowser browser, String parentId, int itemCount, LibraryParams params) {
            parentIdRef.set(parentId);
            itemCountRef.set(itemCount);
            paramsRef.set(params);
            latch.countDown();
        }
    };
    MediaBrowser browser = createBrowser(null, browserListenerProxy);
    LibraryResult<Void> result = threadTestRule.getHandler().postAndSync(() -> browser.subscribe(expectedParentId, null)).get(TIMEOUT_MS, MILLISECONDS);
    assertThat(result.resultCode).isEqualTo(RESULT_SUCCESS);
    // The MediaLibrarySession in MockMediaLibraryService is supposed to call
    // notifyChildrenChanged(ControllerInfo) in its onSubscribe() method.
    assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
    assertThat(parentIdRef.get()).isEqualTo(expectedParentId);
    assertThat(itemCountRef.get()).isEqualTo(NOTIFY_CHILDREN_CHANGED_ITEM_COUNT);
    MediaTestUtils.assertLibraryParamsEquals(paramsRef.get(), NOTIFY_CHILDREN_CHANGED_EXTRAS);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LibraryParams(androidx.media3.session.MediaLibraryService.LibraryParams) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 7 with MediaLibrarySession

use of androidx.media3.session.MediaLibraryService.MediaLibrarySession in project media by androidx.

the class MediaBrowserListenerTest method onChildrenChanged_notCalledWhenNotSubscribed.

@Test
public void onChildrenChanged_notCalledWhenNotSubscribed() throws Exception {
    // This test uses MediaLibrarySession.notifyChildrenChanged().
    String subscribedMediaId = SUBSCRIBE_ID_NOTIFY_CHILDREN_CHANGED_TO_ALL_WITH_NON_SUBSCRIBED_ID;
    CountDownLatch latch = new CountDownLatch(1);
    MediaBrowser.Listener browserListenerProxy = new MediaBrowser.Listener() {

        @Override
        public void onChildrenChanged(MediaBrowser browser, String parentId, int itemCount, LibraryParams params) {
            latch.countDown();
        }
    };
    MediaBrowser browser = createBrowser(null, browserListenerProxy);
    LibraryResult<Void> result = threadTestRule.getHandler().postAndSync(() -> browser.subscribe(subscribedMediaId, null)).get(TIMEOUT_MS, MILLISECONDS);
    assertThat(result.resultCode).isEqualTo(RESULT_SUCCESS);
    // The MediaLibrarySession in MockMediaLibraryService is supposed to call
    // notifyChildrenChanged() in its onSubscribe() method, but with a different media ID.
    // Therefore, onChildrenChanged() should not be called.
    assertThat(latch.await(NO_RESPONSE_TIMEOUT_MS, MILLISECONDS)).isFalse();
}
Also used : LibraryParams(androidx.media3.session.MediaLibraryService.LibraryParams) CountDownLatch(java.util.concurrent.CountDownLatch) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)6 Test (org.junit.Test)6 LibraryParams (androidx.media3.session.MediaLibraryService.LibraryParams)5 LargeTest (androidx.test.filters.LargeTest)4 MediaLibrarySession (androidx.media3.session.MediaLibraryService.MediaLibrarySession)2 ControllerInfo (androidx.media3.session.MediaSession.ControllerInfo)2 MediumTest (androidx.test.filters.MediumTest)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Nullable (androidx.annotation.Nullable)1 MediaLibrarySessionCallback (androidx.media3.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback)1