PlaybackPendingIntentBuilder
@UnstableApi
class PlaybackPendingIntentBuilder
A builder for creating a PendingIntent for a given Player.Command to be sent to a MediaSessionService.
This builder is primarily intended for creating PendingIntent instances used in home screen widgets (see App widgets overview). For other use cases, such as interacting with a Media3 session service from within an app, it is strongly recommended to use a MediaController or MediaBrowser instead of a PendingIntent.
Summary
Public constructors |
|---|
PlaybackPendingIntentBuilder(Creates a builder for a |
Public functions |
|
|---|---|
PendingIntent! |
build()Builds the |
java-static Intent! |
createMediaButtonIntent(Creates an |
java-static Boolean |
isCommandSupported(@Player.Command command: Int)Returns whether the given |
PlaybackPendingIntentBuilder! |
@CanIgnoreReturnValueSets the additional extras of the |
PlaybackPendingIntentBuilder! |
@CanIgnoreReturnValueSets the ID of the session. |
PlaybackPendingIntentBuilder! |
@CanIgnoreReturnValueSets whether the service should be started into the foreground. |
Public constructors
PlaybackPendingIntentBuilder
PlaybackPendingIntentBuilder(
context: Context!,
@Player.Command command: Int,
serviceClass: Class<MediaSessionService!>!
)
Creates a builder for a PendingIntent for a given Player.Command.
Throws an IllegalArgumentException if the Player.Command is not in the set of supported commands. Supported commands are:
COMMAND_PLAY_PAUSECOMMAND_SEEK_BACKCOMMAND_SEEK_FORWARDCOMMAND_SEEK_TO_NEXT_MEDIA_ITEMCOMMAND_SEEK_TO_NEXTCOMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEMCOMMAND_SEEK_TO_PREVIOUSCOMMAND_STOP
| Parameters | |
|---|---|
context: Context! |
The context. |
@Player.Command command: Int |
The |
serviceClass: Class<MediaSessionService!>! |
The class of the service to which the intent should be sent. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
for unsupported |
Public functions
build
fun build(): PendingIntent!
Builds the PendingIntent.
Two PendingIntent instances for the same command are considered the same. The key code of the command is used as the request code.
The PendingIntent is created with the flags PendingIntent.FLAG_UPDATE_CURRENT
| PendingIntent.FLAG_IMMUTABLE.
createMediaButtonIntent
java-static fun createMediaButtonIntent(
context: Context!,
@Player.Command command: Int,
extras: Bundle?,
sessionId: String?,
serviceClass: Class<MediaSessionService!>!
): Intent!
Creates an Intent for a media button event.
Throws an IllegalArgumentException if the Player.Command is not in the set of supported commands. Supported commands are:
COMMAND_PLAY_PAUSECOMMAND_SEEK_BACKCOMMAND_SEEK_FORWARDCOMMAND_SEEK_TO_NEXT_MEDIA_ITEMCOMMAND_SEEK_TO_NEXTCOMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEMCOMMAND_SEEK_TO_PREVIOUSCOMMAND_STOP
| Parameters | |
|---|---|
context: Context! |
The context. |
@Player.Command command: Int |
The |
extras: Bundle? |
The additional extras. |
sessionId: String? |
The ID of the session or null if the default session ID should be used. |
serviceClass: Class<MediaSessionService!>! |
The class of the service to which the intent should be sent. |
isCommandSupported
java-static fun isCommandSupported(@Player.Command command: Int): Boolean
Returns whether the given Player.Command is supported.
| Parameters | |
|---|---|
@Player.Command command: Int |
The |
| Returns | |
|---|---|
Boolean |
Whether the given |
setExtras
@CanIgnoreReturnValue
fun setExtras(extras: Bundle!): PlaybackPendingIntentBuilder!
Sets the additional extras of the Intent.
| Parameters | |
|---|---|
extras: Bundle! |
The additional extras. |
| Returns | |
|---|---|
PlaybackPendingIntentBuilder! |
This builder. |
setSessionId
@CanIgnoreReturnValue
fun setSessionId(sessionId: String?): PlaybackPendingIntentBuilder!
Sets the ID of the session.
The default value is null, which which corresponds to the default ID used when * setId was not called when building the session.
| Parameters | |
|---|---|
sessionId: String? |
The ID of the session as set with |
| Returns | |
|---|---|
PlaybackPendingIntentBuilder! |
This builder. |
setStartAsForegroundService
@CanIgnoreReturnValue
fun setStartAsForegroundService(startAsForegroundService: Boolean): PlaybackPendingIntentBuilder!
Sets whether the service should be started into the foreground.
This is usually the case for the COMMAND_PLAY_PAUSE command only, hence when getPlayWhenReady is false. The default value is false.
| Parameters | |
|---|---|
startAsForegroundService: Boolean |
Whether the service should be started into the foreground. |
| Returns | |
|---|---|
PlaybackPendingIntentBuilder! |
This builder. |