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