mirror of
https://github.com/androidx/media.git
synced 2025-05-10 00:59:51 +08:00
Add ability to register/unregister custom CommandReceivers.
PiperOrigin-RevId: 243799572
This commit is contained in:
parent
c2c7c43a36
commit
9fc3ea79a1
@ -2,6 +2,9 @@
|
||||
|
||||
### dev-v2 (not yet released) ###
|
||||
|
||||
* MediaSession extension:
|
||||
* Allow handling of custom commands via `registerCustomCommandReceiver`.
|
||||
|
||||
### 2.10.0 ###
|
||||
|
||||
* Core library:
|
||||
|
@ -364,6 +364,7 @@ public final class MediaSessionConnector {
|
||||
private final Looper looper;
|
||||
private final ComponentListener componentListener;
|
||||
private final ArrayList<CommandReceiver> commandReceivers;
|
||||
private final ArrayList<CommandReceiver> customCommandReceivers;
|
||||
|
||||
private ControlDispatcher controlDispatcher;
|
||||
private CustomActionProvider[] customActionProviders;
|
||||
@ -392,6 +393,7 @@ public final class MediaSessionConnector {
|
||||
looper = Util.getLooper();
|
||||
componentListener = new ComponentListener();
|
||||
commandReceivers = new ArrayList<>();
|
||||
customCommandReceivers = new ArrayList<>();
|
||||
controlDispatcher = new DefaultControlDispatcher();
|
||||
customActionProviders = new CustomActionProvider[0];
|
||||
customActionMap = Collections.emptyMap();
|
||||
@ -697,6 +699,29 @@ public final class MediaSessionConnector {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a custom command receiver for responding to commands delivered via {@link
|
||||
* MediaSessionCompat.Callback#onCommand(String, Bundle, ResultReceiver)}.
|
||||
*
|
||||
* <p>Commands are only dispatched to this receiver when a player is connected.
|
||||
*
|
||||
* @param commandReceiver The command receiver to register.
|
||||
*/
|
||||
public void registerCustomCommandReceiver(CommandReceiver commandReceiver) {
|
||||
if (!customCommandReceivers.contains(commandReceiver)) {
|
||||
customCommandReceivers.add(commandReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a previously registered custom command receiver.
|
||||
*
|
||||
* @param commandReceiver The command receiver to unregister.
|
||||
*/
|
||||
public void unregisterCustomCommandReceiver(CommandReceiver commandReceiver) {
|
||||
customCommandReceivers.remove(commandReceiver);
|
||||
}
|
||||
|
||||
private void registerCommandReceiver(CommandReceiver commandReceiver) {
|
||||
if (!commandReceivers.contains(commandReceiver)) {
|
||||
commandReceivers.add(commandReceiver);
|
||||
@ -1113,6 +1138,13 @@ public final class MediaSessionConnector {
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < customCommandReceivers.size(); i++) {
|
||||
if (customCommandReceivers
|
||||
.get(i)
|
||||
.onCommand(player, controlDispatcher, command, extras, cb)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user