# CommandButton.Builder

Artifact: [androidx.media3:media3-session](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/session/CommandButton.java+class:androidx.media3.session.CommandButton.Builder)

*** ** * ** ***


```
public final class CommandButton.Builder
```

<br />

*** ** * ** ***

A builder for `https://developer.android.com/reference/androidx/media3/session/CommandButton`.

## Summary

| ### Public constructors |
|---|
| `[Builder](https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#Builder())()` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#Builder(int)` instead to define the `https://developer.android.com/reference/androidx/media3/session/CommandButton.Icon` for this button. <br /> |
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#Builder(int)(@https://developer.android.com/reference/androidx/media3/session/CommandButton.Icon int icon)` Creates a builder. |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/CommandButton` | `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#build()()` Builds a `https://developer.android.com/reference/androidx/media3/session/CommandButton`. |
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setCustomIconResId(int)(@https://developer.android.com/reference/androidx/annotation/DrawableRes int resId)` Sets the fallback resource ID of an icon. |
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setDisplayName(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence.html displayName)` Sets a display name of this button. |
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setEnabled(boolean)(boolean enabled)` Sets whether the button is enabled. |
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setExtras(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html extras)` Sets an extra `https://developer.android.com/reference/android/os/Bundle.html` of this button. |
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html [setIconResId](https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setIconResId(int))(@https://developer.android.com/reference/androidx/annotation/DrawableRes int resId)` **This method is deprecated.** The icon should be defined with the constructor `https://developer.android.com/reference/androidx/media3/session/CommandButton.Icon` parameter in `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#Builder(int)` instead. <br /> |
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setIconUri(android.net.Uri)(https://developer.android.com/reference/android/net/Uri.html uri)` Sets a fallback `https://developer.android.com/reference/android/content/ContentResolver.html#SCHEME_CONTENT` or `https://developer.android.com/reference/android/content/ContentResolver.html#SCHEME_ANDROID_RESOURCE``https://developer.android.com/reference/android/net/Uri.html` for the icon of this button. |
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setPlayerCommand(int)(@https://developer.android.com/reference/androidx/media3/common/Player.Command int playerCommand)` Sets the `https://developer.android.com/reference/androidx/media3/common/Player.Command` that is required to be `https://developer.android.com/reference/androidx/media3/session/MediaController#isCommandAvailable(int)` when the button is clicked. |
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi @https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setPlayerCommand(int,java.lang.Object)( @https://developer.android.com/reference/androidx/media3/common/Player.Command int playerCommand, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html parameter )` Sets the `https://developer.android.com/reference/androidx/media3/common/Player.Command` that is required to be `https://developer.android.com/reference/androidx/media3/session/MediaController#isCommandAvailable(int)` when the button is clicked. |
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setSessionCommand(androidx.media3.session.SessionCommand)(https://developer.android.com/reference/androidx/media3/session/SessionCommand sessionCommand)` Sets the `https://developer.android.com/reference/androidx/media3/session/SessionCommand` that is required to be `https://developer.android.com/reference/androidx/media3/session/MediaController#isSessionCommandAvailable(int)` when the button is clicked. |
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html @https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setSessionCommand(androidx.media3.session.SessionCommand,java.lang.Object)( https://developer.android.com/reference/androidx/media3/session/SessionCommand sessionCommand, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html parameter )` Sets the `https://developer.android.com/reference/androidx/media3/session/SessionCommand` that is required to be `https://developer.android.com/reference/androidx/media3/session/MediaController#isSessionCommandAvailable(int)` when the button is clicked. |
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi @https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setSlots(int...)(@https://developer.android.com/reference/androidx/media3/session/CommandButton.Slot int[] slots)` Sets the allowed `https://developer.android.com/reference/androidx/media3/session/CommandButton.Slot` positions for this button. |

## Public constructors

### Builder

```
public [Builder](https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#Builder())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#Builder(int)` instead to define the `https://developer.android.com/reference/androidx/media3/session/CommandButton.Icon` for this button. A separate resource id via `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setIconResId(int)` is no longer required unless for `https://developer.android.com/reference/androidx/media3/session/CommandButton#ICON_UNDEFINED()`.

### Builder

```
public Builder(@CommandButton.Icon int icon)
```

Creates a builder.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/session/CommandButton.Icon int icon` | The `https://developer.android.com/reference/androidx/media3/session/CommandButton.Icon` that should be shown for this button. |

## Public methods

### build

```
public CommandButton build()
```

Builds a `https://developer.android.com/reference/androidx/media3/session/CommandButton`.

### setCustomIconResId

```
@CanIgnoreReturnValue
public CommandButton.Builder setCustomIconResId(@DrawableRes int resId)
```

Sets the fallback resource ID of an icon.

This is used when either the predefined `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#icon()` is not available, or it's set to `https://developer.android.com/reference/androidx/media3/session/CommandButton#ICON_UNDEFINED()`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/DrawableRes int resId` | The resource id of a custom icon. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | This builder for chaining. |

### setDisplayName

```
@CanIgnoreReturnValue
public CommandButton.Builder setDisplayName(CharSequence displayName)
```

Sets a display name of this button.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence.html displayName` | The display name. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | This builder for chaining. |

### setEnabled

```
@CanIgnoreReturnValue
public CommandButton.Builder setEnabled(boolean enabled)
```

Sets whether the button is enabled.

Note that this value will be set to `false` for `https://developer.android.com/reference/androidx/media3/session/MediaController` instances if the corresponding command is not available to this controller (see `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setPlayerCommand(int)` and `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setSessionCommand(androidx.media3.session.SessionCommand)`).

The default value is `true`.

| Parameters |
|---|---|
| `boolean enabled` | Whether the button is enabled. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | This builder for chaining. |

### setExtras

```
@CanIgnoreReturnValue
public CommandButton.Builder setExtras(Bundle extras)
```

Sets an extra `https://developer.android.com/reference/android/os/Bundle.html` of this button.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/os/Bundle.html extras` | The extra `https://developer.android.com/reference/android/os/Bundle.html`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | This builder for chaining. |

### setIconResId

```
@CanIgnoreReturnValue
public CommandButton.Builder [setIconResId](https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setIconResId(int))(@DrawableRes int resId)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> The icon should be defined with the constructor `https://developer.android.com/reference/androidx/media3/session/CommandButton.Icon` parameter in `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#Builder(int)` instead. If the existing list of icons is not sufficient, use `https://developer.android.com/reference/androidx/media3/session/CommandButton#ICON_UNDEFINED()` for the constructor `https://developer.android.com/reference/androidx/media3/session/CommandButton.Icon` parameter, and set a separate resource id with `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setCustomIconResId(int)`.

### setIconUri

```
@CanIgnoreReturnValue
public CommandButton.Builder setIconUri(Uri uri)
```

Sets a fallback `https://developer.android.com/reference/android/content/ContentResolver.html#SCHEME_CONTENT` or `https://developer.android.com/reference/android/content/ContentResolver.html#SCHEME_ANDROID_RESOURCE``https://developer.android.com/reference/android/net/Uri.html` for the icon of this button.

Note that this `https://developer.android.com/reference/android/net/Uri.html` may be used when either the predefined `https://developer.android.com/reference/androidx/media3/session/CommandButton#icon()` is not available, or it's set to `https://developer.android.com/reference/androidx/media3/session/CommandButton#ICON_UNDEFINED()`. It can be used in addition to `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setCustomIconResId(int)` for consumers that are capable of loading the content or resource `https://developer.android.com/reference/android/net/Uri.html`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/net/Uri.html uri` | The uri to an icon. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | This builder for chaining. |

### setPlayerCommand

```
@CanIgnoreReturnValue
public CommandButton.Builder setPlayerCommand(@Player.Command int playerCommand)
```

Sets the `https://developer.android.com/reference/androidx/media3/common/Player.Command` that is required to be `https://developer.android.com/reference/androidx/media3/session/MediaController#isCommandAvailable(int)` when the button is clicked.

Cannot set this if a session command is already set via `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setSessionCommand(androidx.media3.session.SessionCommand)`.

The controller can execute the action associated with this command. See `https://developer.android.com/reference/androidx/media3/session/CommandButton#executeAction(androidx.media3.session.MediaController)` for a list of supported actions. If the action requires an additional parameter, use `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setPlayerCommand(int,java.lang.Object)` instead.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/common/Player.Command int playerCommand` | The `https://developer.android.com/reference/androidx/media3/common/Player.Command`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | This builder for chaining. |

### setPlayerCommand

```
@UnstableApi
@CanIgnoreReturnValue
public CommandButton.Builder setPlayerCommand(
    @Player.Command int playerCommand,
    @Nullable Object parameter
)
```

Sets the `https://developer.android.com/reference/androidx/media3/common/Player.Command` that is required to be `https://developer.android.com/reference/androidx/media3/session/MediaController#isCommandAvailable(int)` when the button is clicked.

Cannot set this if a session command is already set via `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setSessionCommand(androidx.media3.session.SessionCommand)`.

The controller can execute the action associated with this command. See `https://developer.android.com/reference/androidx/media3/session/CommandButton#executeAction(androidx.media3.session.MediaController)` for a list of supported actions. If the action requires no additional parameter, use `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setPlayerCommand(int)` instead.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/common/Player.Command int playerCommand` | The `https://developer.android.com/reference/androidx/media3/common/Player.Command`. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html parameter` | The parameter required to execute the action associated with this command. See `https://developer.android.com/reference/androidx/media3/session/CommandButton#executeAction(androidx.media3.session.MediaController)` for a list of supported actions and parameter types. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | This builder for chaining. |

### setSessionCommand

```
@CanIgnoreReturnValue
public CommandButton.Builder setSessionCommand(SessionCommand sessionCommand)
```

Sets the `https://developer.android.com/reference/androidx/media3/session/SessionCommand` that is required to be `https://developer.android.com/reference/androidx/media3/session/MediaController#isSessionCommandAvailable(int)` when the button is clicked.

Cannot set this if a player command is already set via `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setPlayerCommand(int)`.

The controller can execute the action associated with this command. See `https://developer.android.com/reference/androidx/media3/session/CommandButton#executeAction(androidx.media3.session.MediaController)` for a list of supported actions. If the action requires an additional parameter, use `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setSessionCommand(androidx.media3.session.SessionCommand,java.lang.Object)` instead.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/SessionCommand sessionCommand` | The `https://developer.android.com/reference/androidx/media3/session/SessionCommand`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | This builder for chaining. |

### setSessionCommand

```
@CanIgnoreReturnValue
@UnstableApi
public CommandButton.Builder setSessionCommand(
    SessionCommand sessionCommand,
    @Nullable Object parameter
)
```

Sets the `https://developer.android.com/reference/androidx/media3/session/SessionCommand` that is required to be `https://developer.android.com/reference/androidx/media3/session/MediaController#isSessionCommandAvailable(int)` when the button is clicked.

Cannot set this if a player command is already set via `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setPlayerCommand(int)`.

The controller can execute the action associated with this command. See `https://developer.android.com/reference/androidx/media3/session/CommandButton#executeAction(androidx.media3.session.MediaController)` for a list of supported actions. If the action requires no additional parameter, use `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setSessionCommand(androidx.media3.session.SessionCommand)` instead.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/SessionCommand sessionCommand` | The `https://developer.android.com/reference/androidx/media3/session/SessionCommand`. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html parameter` | The parameter required to execute the action associated with this command. See `https://developer.android.com/reference/androidx/media3/session/CommandButton#executeAction(androidx.media3.session.MediaController)` for a list of supported actions and parameter types. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | This builder for chaining. |

### setSlots

```
@UnstableApi
@CanIgnoreReturnValue
public CommandButton.Builder setSlots(@CommandButton.Slot int[] slots)
```

Sets the allowed `https://developer.android.com/reference/androidx/media3/session/CommandButton.Slot` positions for this button.

The button is only allowed in the defined slots. If none of the slots can display the button, either because the slots do not exist, are already occupied or the UI surface does not allow the specific type of button in these slots, the button will not be displayed at all.

When multiple slots are provided, they define a preference order. The button will be placed in the first slot in the list that exists, isn't already occupied and that allows this type of button.

When not specified, the default value depends on the associated `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder#setPlayerCommand(int)` and the `https://developer.android.com/reference/androidx/media3/session/CommandButton.Icon` set in the constructor:

- `https://developer.android.com/reference/androidx/media3/common/Player#COMMAND_PLAY_PAUSE()` and/or `https://developer.android.com/reference/androidx/media3/session/CommandButton#ICON_PLAY()`, `https://developer.android.com/reference/androidx/media3/session/CommandButton#ICON_PAUSE()`: `https://developer.android.com/reference/androidx/media3/session/CommandButton#SLOT_CENTRAL()`
- `https://developer.android.com/reference/androidx/media3/common/Player#COMMAND_SEEK_TO_PREVIOUS()`, `https://developer.android.com/reference/androidx/media3/common/Player#COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM()`, `https://developer.android.com/reference/androidx/media3/common/Player#COMMAND_SEEK_BACK()` and/or `https://developer.android.com/reference/androidx/media3/session/CommandButton#ICON_PREVIOUS()`, `https://developer.android.com/reference/androidx/media3/session/CommandButton#ICON_SKIP_BACK()`, `https://developer.android.com/reference/androidx/media3/session/CommandButton#ICON_REWIND()`: `https://developer.android.com/reference/androidx/media3/session/CommandButton#SLOT_BACK()`
- `https://developer.android.com/reference/androidx/media3/common/Player#COMMAND_SEEK_TO_NEXT()`, `https://developer.android.com/reference/androidx/media3/common/Player#COMMAND_SEEK_TO_NEXT_MEDIA_ITEM()`, `https://developer.android.com/reference/androidx/media3/common/Player#COMMAND_SEEK_FORWARD()` and/or `https://developer.android.com/reference/androidx/media3/session/CommandButton#ICON_NEXT()`, `https://developer.android.com/reference/androidx/media3/session/CommandButton#ICON_SKIP_FORWARD()`, `https://developer.android.com/reference/androidx/media3/session/CommandButton#ICON_FAST_FORWARD()`: `https://developer.android.com/reference/androidx/media3/session/CommandButton#SLOT_FORWARD()`
- Anything else: `https://developer.android.com/reference/androidx/media3/session/CommandButton#SLOT_OVERFLOW()`

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/session/CommandButton.Slot int[] slots` | The list of allowed `https://developer.android.com/reference/androidx/media3/session/CommandButton.Slot` positions. Must not be empty. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/CommandButton.Builder` | This builder for chaining. |