Skip to content

Commit 2c08068

Browse files
Document custom commands in the DefaultMediaNotificationProvider
Issue: #103 #minor-release PiperOrigin-RevId: 458465479
1 parent c9abe70 commit 2c08068

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

libraries/session/src/main/java/androidx/media3/session/DefaultMediaNotificationProvider.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@
6969
* <li>{@link MediaController#COMMAND_SEEK_TO_NEXT} to seek to the next item.
7070
* </ul>
7171
*
72+
* <h2>Custom commands</h2>
73+
*
74+
* Custom actions are sent to the session under the hood. You can receive them by overriding the
75+
* session callback method {@link MediaSession.Callback#onCustomCommand(MediaSession, ControllerInfo
76+
* controller, SessionCommand, Bundle)}. This is useful because starting with Android 13, the System
77+
* UI notification sends commands directly to the session. So handling the custom commands on the
78+
* session level allows you to handle them at the same callback for all API levels.
79+
*
7280
* <h2>Drawables</h2>
7381
*
7482
* The drawables used can be overridden by drawables with the same names defined the application.
@@ -219,6 +227,14 @@ public final boolean handleCustomCommand(MediaSession session, String action, Bu
219227
* customized by defining the index of the command in compact view of up to 3 commands in their
220228
* extras with key {@link DefaultMediaNotificationProvider#COMMAND_KEY_COMPACT_VIEW_INDEX}.
221229
*
230+
* <p>To make the custom layout and commands work, you need to {@linkplain
231+
* MediaSession#setCustomLayout(List) set the custom layout of commands} and add the custom
232+
* commands to the available commands when a controller {@linkplain
233+
* MediaSession.Callback#onConnect(MediaSession, ControllerInfo) connects to the session}.
234+
* Controllers that connect after you called {@link MediaSession#setCustomLayout(List)} need the
235+
* custom command set in {@link MediaSession.Callback#onPostConnect(MediaSession, ControllerInfo)}
236+
* also.
237+
*
222238
* @param playerCommands The available player commands.
223239
* @param customLayout The {@linkplain MediaSession#setCustomLayout(List) custom layout of
224240
* commands}.

0 commit comments

Comments
 (0)