use of android.support.v4.media.MediaBrowserCompat.ItemCallback in project media by androidx.
the class MediaBrowserImplLegacy method getItem.
@Override
public ListenableFuture<LibraryResult<MediaItem>> getItem(String mediaId) {
if (!instance.isSessionCommandAvailable(SessionCommand.COMMAND_CODE_LIBRARY_GET_ITEM)) {
return Futures.immediateFuture(LibraryResult.ofError(RESULT_ERROR_PERMISSION_DENIED));
}
MediaBrowserCompat browserCompat = getBrowserCompat();
if (browserCompat == null) {
return Futures.immediateFuture(LibraryResult.ofError(RESULT_ERROR_SESSION_DISCONNECTED));
}
SettableFuture<LibraryResult<MediaItem>> result = SettableFuture.create();
browserCompat.getItem(mediaId, new ItemCallback() {
@Override
public void onItemLoaded(MediaBrowserCompat.MediaItem item) {
if (item != null) {
result.set(LibraryResult.ofItem(MediaUtils.convertToMediaItem(item), /* params= */
null));
} else {
result.set(LibraryResult.ofError(RESULT_ERROR_BAD_VALUE));
}
}
@Override
public void onError(String itemId) {
result.set(LibraryResult.ofError(RESULT_ERROR_UNKNOWN));
}
});
return result;
}
use of android.support.v4.media.MediaBrowserCompat.ItemCallback in project media by androidx.
the class MediaBrowserCompatWithMediaLibraryServiceTest method getItem_nullResult.
@Test
public void getItem_nullResult() throws InterruptedException {
String mediaId = "random_media_id";
connectAndWait();
CountDownLatch latch = new CountDownLatch(1);
browserCompat.getItem(mediaId, new ItemCallback() {
@Override
public void onItemLoaded(MediaItem item) {
assertThat(item).isNull();
latch.countDown();
}
@Override
public void onError(String itemId) {
assertWithMessage("").fail();
}
});
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
}
use of android.support.v4.media.MediaBrowserCompat.ItemCallback in project media by androidx.
the class MediaBrowserCompatWithMediaLibraryServiceTest method getItem_playable.
@Test
public void getItem_playable() throws InterruptedException {
String mediaId = MEDIA_ID_GET_PLAYABLE_ITEM;
connectAndWait();
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<MediaItem> itemRef = new AtomicReference<>();
browserCompat.getItem(mediaId, new ItemCallback() {
@Override
public void onItemLoaded(MediaItem item) {
itemRef.set(item);
latch.countDown();
}
});
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(itemRef.get().getMediaId()).isEqualTo(mediaId);
assertThat(itemRef.get().isPlayable()).isTrue();
}
use of android.support.v4.media.MediaBrowserCompat.ItemCallback in project media by androidx.
the class MediaBrowserCompatWithMediaLibraryServiceTest method getItem_metadata.
@Test
public void getItem_metadata() throws InterruptedException {
String mediaId = MEDIA_ID_GET_ITEM_WITH_METADATA;
connectAndWait();
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<MediaItem> itemRef = new AtomicReference<>();
browserCompat.getItem(mediaId, new ItemCallback() {
@Override
public void onItemLoaded(MediaItem item) {
itemRef.set(item);
latch.countDown();
}
});
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(itemRef.get().getMediaId()).isEqualTo(mediaId);
MediaDescriptionCompat description = itemRef.get().getDescription();
assertThat(TextUtils.equals(description.getTitle(), METADATA_TITLE)).isTrue();
assertThat(TextUtils.equals(description.getSubtitle(), METADATA_SUBTITLE)).isTrue();
assertThat(TextUtils.equals(description.getDescription(), METADATA_DESCRIPTION)).isTrue();
assertThat(description.getIconUri()).isEqualTo(METADATA_ARTWORK_URI);
assertThat(description.getMediaUri()).isEqualTo(METADATA_MEDIA_URI);
BundleSubject.assertThat(description.getExtras()).string(METADATA_EXTRA_KEY).isEqualTo(METADATA_EXTRA_VALUE);
}
use of android.support.v4.media.MediaBrowserCompat.ItemCallback in project media by androidx.
the class MediaBrowserCompatWithMediaLibraryServiceTest method getItem_browsable.
@Test
public void getItem_browsable() throws InterruptedException {
String mediaId = MEDIA_ID_GET_BROWSABLE_ITEM;
connectAndWait();
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<MediaItem> itemRef = new AtomicReference<>();
browserCompat.getItem(mediaId, new ItemCallback() {
@Override
public void onItemLoaded(MediaItem item) {
itemRef.set(item);
latch.countDown();
}
});
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(itemRef.get().getMediaId()).isEqualTo(mediaId);
assertThat(itemRef.get().isBrowsable()).isTrue();
}
Aggregations