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);
}
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();
}
Aggregations