mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Fix supportedCommands in MediaMetadata
#cherrypick PiperOrigin-RevId: 695304782
This commit is contained in:
parent
0c982a7994
commit
fa790bd73c
@ -36,6 +36,7 @@ import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ -611,6 +612,10 @@ public final class MediaMetadata {
|
||||
setExtras(mediaMetadata.extras);
|
||||
}
|
||||
|
||||
if (!mediaMetadata.supportedCommands.isEmpty()) {
|
||||
setSupportedCommands(mediaMetadata.supportedCommands);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -1249,6 +1254,7 @@ public final class MediaMetadata {
|
||||
&& Util.areEqual(compilation, that.compilation)
|
||||
&& Util.areEqual(station, that.station)
|
||||
&& Util.areEqual(mediaType, that.mediaType)
|
||||
&& Util.areEqual(supportedCommands, that.supportedCommands)
|
||||
&& ((extras == null) == (that.extras == null));
|
||||
}
|
||||
|
||||
@ -1289,7 +1295,8 @@ public final class MediaMetadata {
|
||||
compilation,
|
||||
station,
|
||||
mediaType,
|
||||
extras == null);
|
||||
extras == null,
|
||||
supportedCommands);
|
||||
}
|
||||
|
||||
private static final String FIELD_TITLE = Util.intToStringMaxRadix(0);
|
||||
@ -1326,6 +1333,7 @@ public final class MediaMetadata {
|
||||
private static final String FIELD_MEDIA_TYPE = Util.intToStringMaxRadix(31);
|
||||
private static final String FIELD_IS_BROWSABLE = Util.intToStringMaxRadix(32);
|
||||
private static final String FIELD_DURATION_MS = Util.intToStringMaxRadix(33);
|
||||
private static final String FIELD_SUPPORTED_COMMANDS = Util.intToStringMaxRadix(34);
|
||||
private static final String FIELD_EXTRAS = Util.intToStringMaxRadix(1000);
|
||||
|
||||
@SuppressWarnings("deprecation") // Bundling deprecated fields.
|
||||
@ -1431,6 +1439,9 @@ public final class MediaMetadata {
|
||||
if (mediaType != null) {
|
||||
bundle.putInt(FIELD_MEDIA_TYPE, mediaType);
|
||||
}
|
||||
if (!supportedCommands.isEmpty()) {
|
||||
bundle.putStringArrayList(FIELD_SUPPORTED_COMMANDS, new ArrayList<>(supportedCommands));
|
||||
}
|
||||
if (extras != null) {
|
||||
bundle.putBundle(FIELD_EXTRAS, extras);
|
||||
}
|
||||
@ -1521,6 +1532,11 @@ public final class MediaMetadata {
|
||||
if (bundle.containsKey(FIELD_MEDIA_TYPE)) {
|
||||
builder.setMediaType(bundle.getInt(FIELD_MEDIA_TYPE));
|
||||
}
|
||||
@Nullable
|
||||
ArrayList<String> supportedCommands = bundle.getStringArrayList(FIELD_SUPPORTED_COMMANDS);
|
||||
if (supportedCommands != null) {
|
||||
builder.setSupportedCommands(supportedCommands);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@ -68,6 +69,7 @@ public class MediaMetadataTest {
|
||||
assertThat(mediaMetadata.compilation).isNull();
|
||||
assertThat(mediaMetadata.station).isNull();
|
||||
assertThat(mediaMetadata.mediaType).isNull();
|
||||
assertThat(mediaMetadata.supportedCommands).isEmpty();
|
||||
assertThat(mediaMetadata.extras).isNull();
|
||||
}
|
||||
|
||||
@ -278,6 +280,7 @@ public class MediaMetadataTest {
|
||||
.setCompilation("Amazing songs.")
|
||||
.setStation("radio station")
|
||||
.setMediaType(MediaMetadata.MEDIA_TYPE_MIXED)
|
||||
.setSupportedCommands(ImmutableList.of("command1", "command2"))
|
||||
.setExtras(extras)
|
||||
.build();
|
||||
}
|
||||
|
@ -2052,24 +2052,14 @@ public class MediaControllerTest {
|
||||
.setSessionCommand(
|
||||
new SessionCommand(MediaBrowserConstants.COMMAND_RADIO, Bundle.EMPTY))
|
||||
.build();
|
||||
MediaItem mediaItem =
|
||||
new MediaItem.Builder()
|
||||
.setMediaId("mediaId")
|
||||
.setMediaMetadata(
|
||||
new MediaMetadata.Builder()
|
||||
.setSupportedCommands(
|
||||
ImmutableList.of(
|
||||
MediaBrowserConstants.COMMAND_PLAYLIST_ADD,
|
||||
MediaBrowserConstants.COMMAND_RADIO,
|
||||
"invalid"))
|
||||
.build())
|
||||
.build();
|
||||
MediaController controller = controllerTestRule.createController(session.getToken());
|
||||
MediaItem currentMediaItem =
|
||||
threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItem);
|
||||
|
||||
ImmutableList<CommandButton> commandButtons =
|
||||
threadTestRule
|
||||
.getHandler()
|
||||
.postAndSync(() -> controller.getCommandButtonsForMediaItem(mediaItem));
|
||||
.postAndSync(() -> controller.getCommandButtonsForMediaItem(currentMediaItem));
|
||||
|
||||
assertThat(commandButtons).containsExactly(playlistAddButton, radioButton).inOrder();
|
||||
session.cleanUp();
|
||||
|
@ -253,6 +253,20 @@ public class MediaSessionProviderService extends Service {
|
||||
.build();
|
||||
builder.setCommandButtonsForMediaItems(
|
||||
ImmutableList.of(playlistAddButton, radioButton));
|
||||
mockPlayer.timeline =
|
||||
new PlaylistTimeline(
|
||||
ImmutableList.of(
|
||||
new MediaItem.Builder()
|
||||
.setMediaId("mediaIdWithSupportedCommands")
|
||||
.setMediaMetadata(
|
||||
new MediaMetadata.Builder()
|
||||
.setSupportedCommands(
|
||||
ImmutableList.of(
|
||||
MediaBrowserConstants.COMMAND_PLAYLIST_ADD,
|
||||
MediaBrowserConstants.COMMAND_RADIO,
|
||||
"invalid"))
|
||||
.build())
|
||||
.build()));
|
||||
builder.setCallback(
|
||||
new MediaSession.Callback() {
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user