Commit e0bb23d4 by tonihei Committed by Rohit Singh

Remove unnecessary check for currentMediaItem in legacy session stub

This check was a leftover from when the metadata was generated from
the MediaItem only. Since we moved to the actual MediaMetadata fields,
the check is completely unnecessary and prevents accessing metadata
when the GET_CURRENT_MEDIA_ITEM command is not available.

#minor-release

PiperOrigin-RevId: 524837587
parent b61abefd
...@@ -52,6 +52,8 @@ ...@@ -52,6 +52,8 @@
`MediaController` are ignored if they reference a group with `MediaController` are ignored if they reference a group with
`Format.metadata` `Format.metadata`
([#296](https://github.com/androidx/media/issues/296)). ([#296](https://github.com/androidx/media/issues/296)).
* Fix issue where `Player.COMMAND_GET_CURRENT_MEDIA_ITEM` needs to be
available to access metadata via the legacy `MediaSessionCompat`.
* Audio: * Audio:
* Fix bug where some playbacks fail when tunneling is enabled and * Fix bug where some playbacks fail when tunneling is enabled and
`AudioProcessors` are active, e.g. for gapless trimming `AudioProcessors` are active, e.g. for gapless trimming
......
...@@ -1322,11 +1322,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -1322,11 +1322,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
lastMediaMetadata = newMediaMetadata; lastMediaMetadata = newMediaMetadata;
lastDurationMs = newDurationMs; lastDurationMs = newDurationMs;
if (currentMediaItem == null) {
setMetadata(sessionCompat, /* metadataCompat= */ null);
return;
}
@Nullable Bitmap artworkBitmap = null; @Nullable Bitmap artworkBitmap = null;
ListenableFuture<Bitmap> bitmapFuture = ListenableFuture<Bitmap> bitmapFuture =
sessionImpl.getBitmapLoader().loadBitmapFromMetadata(newMediaMetadata); sessionImpl.getBitmapLoader().loadBitmapFromMetadata(newMediaMetadata);
......
...@@ -1085,7 +1085,8 @@ public class MediaControllerCompatCallbackWithMediaSessionTest { ...@@ -1085,7 +1085,8 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
} }
@Test @Test
public void onMediaMetadataChanged_updatesLegacyMetadata_correctModelConversion() public void
onMediaMetadataChanged_withGetMetadataAndGetCurrentMediaItemCommand_updatesLegacyMetadata()
throws Exception { throws Exception {
int testItemIndex = 3; int testItemIndex = 3;
String testDisplayTitle = "displayTitle"; String testDisplayTitle = "displayTitle";
...@@ -1100,6 +1101,12 @@ public class MediaControllerCompatCallbackWithMediaSessionTest { ...@@ -1100,6 +1101,12 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
.setMediaId(testMediaItems.get(testItemIndex).mediaId) .setMediaId(testMediaItems.get(testItemIndex).mediaId)
.setMediaMetadata(testMediaMetadata) .setMediaMetadata(testMediaMetadata)
.build()); .build());
session
.getMockPlayer()
.notifyAvailableCommandsChanged(
new Player.Commands.Builder()
.addAll(Player.COMMAND_GET_METADATA, Player.COMMAND_GET_CURRENT_MEDIA_ITEM)
.build());
session.getMockPlayer().setTimeline(new PlaylistTimeline(testMediaItems)); session.getMockPlayer().setTimeline(new PlaylistTimeline(testMediaItems));
session.getMockPlayer().setCurrentMediaItemIndex(testItemIndex); session.getMockPlayer().setCurrentMediaItemIndex(testItemIndex);
session.getMockPlayer().setDuration(testDurationMs); session.getMockPlayer().setDuration(testDurationMs);
...@@ -1132,6 +1139,49 @@ public class MediaControllerCompatCallbackWithMediaSessionTest { ...@@ -1132,6 +1139,49 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
} }
@Test @Test
public void onMediaMetadataChanged_withGetMetadataCommandOnly_updatesLegacyMetadata()
throws Exception {
int testItemIndex = 3;
String testDisplayTitle = "displayTitle";
List<MediaItem> testMediaItems = MediaTestUtils.createMediaItems(/* size= */ 5);
MediaMetadata testMediaMetadata =
new MediaMetadata.Builder().setTitle(testDisplayTitle).build();
testMediaItems.set(
testItemIndex,
new MediaItem.Builder()
.setMediaId(testMediaItems.get(testItemIndex).mediaId)
.setMediaMetadata(testMediaMetadata)
.build());
session
.getMockPlayer()
.notifyAvailableCommandsChanged(
new Player.Commands.Builder().add(Player.COMMAND_GET_METADATA).build());
session.getMockPlayer().setTimeline(new PlaylistTimeline(testMediaItems));
session.getMockPlayer().setCurrentMediaItemIndex(testItemIndex);
AtomicReference<MediaMetadataCompat> metadataRef = new AtomicReference<>();
CountDownLatch latchForMetadata = new CountDownLatch(1);
MediaControllerCompat.Callback callback =
new MediaControllerCompat.Callback() {
@Override
public void onMetadataChanged(MediaMetadataCompat metadata) {
metadataRef.set(metadata);
latchForMetadata.countDown();
}
};
controllerCompat.registerCallback(callback, handler);
session.getMockPlayer().notifyMediaMetadataChanged(testMediaMetadata);
assertThat(latchForMetadata.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
MediaMetadataCompat parameterMetadataCompat = metadataRef.get();
MediaMetadataCompat getterMetadataCompat = controllerCompat.getMetadata();
assertThat(parameterMetadataCompat.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE))
.isEqualTo(testDisplayTitle);
assertThat(getterMetadataCompat.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE))
.isEqualTo(testDisplayTitle);
}
@Test
public void playlistChange() throws Exception { public void playlistChange() throws Exception {
AtomicReference<List<QueueItem>> queueRef = new AtomicReference<>(); AtomicReference<List<QueueItem>> queueRef = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment