# SessionCommand

# SessionCommand

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/SessionCommand.java+class:androidx.media3.session.SessionCommand)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/session/SessionCommand "View this page in Java")

<br />

```
class SessionCommand
```

<br />

*** ** * ** ***

A command that a[MediaController](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaController)can send to a[MediaSession](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaSession).

If[commandCode](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#commandCode())isn't[COMMAND_CODE_CUSTOM](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#COMMAND_CODE_CUSTOM()), it's a predefined command. If[commandCode](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#commandCode())is[COMMAND_CODE_CUSTOM](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#COMMAND_CODE_CUSTOM()), it's a custom command and[customAction](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#customAction())must not be`null`.

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                        ### Nested types                                                                                                                                                                                                                                                                                                                                                                                                        |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `@`[Documented](https://developer.android.com/reference/java/lang/annotation/Documented.html) `@`[Retention](https://developer.android.com/reference/java/lang/annotation/Retention.html)`(value = `[RetentionPolicy.SOURCE](https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE)`)` `@`[Target](https://developer.android.com/reference/java/lang/annotation/Target.html)`(value = `[ElementType.TYPE_USE](https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE)`)` `@`[IntDef](https://developer.android.com/reference/kotlin/androidx/annotation/IntDef)`(value = )` `annotation `[SessionCommand.CommandCode](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand.CommandCode) Command codes of session commands. |

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [COMMAND_CODE_CUSTOM](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#COMMAND_CODE_CUSTOM())` = 0` Command code for the custom command which can be defined by string action in the[SessionCommand](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand).                                                                              |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [COMMAND_CODE_LIBRARY_GET_CHILDREN](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_GET_CHILDREN())` = 50003` Command code for[getChildren](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#getChildren(java.lang.String,int,int,androidx.media3.session.MediaLibraryService.LibraryParams)).                   |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [COMMAND_CODE_LIBRARY_GET_ITEM](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_GET_ITEM())` = 50004` Command code for[getItem](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#getItem(java.lang.String)).                                                                                                     |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [COMMAND_CODE_LIBRARY_GET_LIBRARY_ROOT](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_GET_LIBRARY_ROOT())` = 50000` Command code for[getLibraryRoot](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#getLibraryRoot(androidx.media3.session.MediaLibraryService.LibraryParams)).                              |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [COMMAND_CODE_LIBRARY_GET_SEARCH_RESULT](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_GET_SEARCH_RESULT())` = 50006` Command code for[getSearchResult](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#getSearchResult(java.lang.String,int,int,androidx.media3.session.MediaLibraryService.LibraryParams)). |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [COMMAND_CODE_LIBRARY_SEARCH](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_SEARCH())` = 50005` Command code for[search](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#search(java.lang.String,androidx.media3.session.MediaLibraryService.LibraryParams)).                                                 |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [COMMAND_CODE_LIBRARY_SUBSCRIBE](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_SUBSCRIBE())` = 50001` Command code for[subscribe](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#subscribe(java.lang.String,androidx.media3.session.MediaLibraryService.LibraryParams)).                                     |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [COMMAND_CODE_LIBRARY_UNSUBSCRIBE](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_UNSUBSCRIBE())` = 50002` Command code for[unsubscribe](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#unsubscribe(java.lang.String)).                                                                                       |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [COMMAND_CODE_SESSION_SET_RATING](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#COMMAND_CODE_SESSION_SET_RATING())` = 40010` Command code for[setRating](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaController#setRating(java.lang.String,androidx.media3.common.Rating)).                                                            |

|                                                                                                                                                                                  ### Public constructors                                                                                                                                                                                   |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SessionCommand](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#SessionCommand(int))`(@`[SessionCommand.CommandCode](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand.CommandCode)` commandCode: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Creates a predefined command. |
| [SessionCommand](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#SessionCommand(java.lang.String,android.os.Bundle))`(action: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!, extras: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`!)` Creates a custom command.                  |

|                                                   ### Public functions                                                   |
|--------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                      | [equals](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#equals(java.lang.Object))`(obj: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?)` Checks the given session command for equality while ignoring extras.                                                                                                                                                        |
| `java-static `[SessionCommand](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand)`!` | `@`[UnstableApi](https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi) [fromBundle](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#fromBundle(android.os.Bundle))`(bundle: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`!)` Restores a`SessionCommand`from a[Bundle](https://developer.android.com/reference/android/os/Bundle.html). |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                              | [hashCode](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#hashCode())`()`                                                                                                                                                                                                                                                                                                                            |
| [Bundle](https://developer.android.com/reference/android/os/Bundle.html)`!`                                              | `@`[UnstableApi](https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi) [toBundle](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#toBundle())`()`                                                                                                                                                                                                                   |

|                                ### Public properties                                 |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | `@`[SessionCommand.CommandCode](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand.CommandCode) [commandCode](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#commandCode()) The command code of a predefined command. |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | [customAction](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#customAction()) The action of a custom command.                                                                                                                                            |
| [Bundle](https://developer.android.com/reference/android/os/Bundle.html)`!`          | [customExtras](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#customExtras()) The extra bundle of a custom command.                                                                                                                                      |

## Constants

### COMMAND_CODE_CUSTOM

```
const val COMMAND_CODE_CUSTOM = 0: Int
```

Command code for the custom command which can be defined by string action in the[SessionCommand](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand).  

### COMMAND_CODE_LIBRARY_GET_CHILDREN

```
const val COMMAND_CODE_LIBRARY_GET_CHILDREN = 50003: Int
```

Command code for[getChildren](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#getChildren(java.lang.String,int,int,androidx.media3.session.MediaLibraryService.LibraryParams)).  

### COMMAND_CODE_LIBRARY_GET_ITEM

```
const val COMMAND_CODE_LIBRARY_GET_ITEM = 50004: Int
```

Command code for[getItem](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#getItem(java.lang.String)).  

### COMMAND_CODE_LIBRARY_GET_LIBRARY_ROOT

```
const val COMMAND_CODE_LIBRARY_GET_LIBRARY_ROOT = 50000: Int
```

Command code for[getLibraryRoot](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#getLibraryRoot(androidx.media3.session.MediaLibraryService.LibraryParams)).  

### COMMAND_CODE_LIBRARY_GET_SEARCH_RESULT

```
const val COMMAND_CODE_LIBRARY_GET_SEARCH_RESULT = 50006: Int
```

Command code for[getSearchResult](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#getSearchResult(java.lang.String,int,int,androidx.media3.session.MediaLibraryService.LibraryParams)).  

### COMMAND_CODE_LIBRARY_SEARCH

```
const val COMMAND_CODE_LIBRARY_SEARCH = 50005: Int
```

Command code for[search](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#search(java.lang.String,androidx.media3.session.MediaLibraryService.LibraryParams)).  

### COMMAND_CODE_LIBRARY_SUBSCRIBE

```
const val COMMAND_CODE_LIBRARY_SUBSCRIBE = 50001: Int
```

Command code for[subscribe](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#subscribe(java.lang.String,androidx.media3.session.MediaLibraryService.LibraryParams)).  

### COMMAND_CODE_LIBRARY_UNSUBSCRIBE

```
const val COMMAND_CODE_LIBRARY_UNSUBSCRIBE = 50002: Int
```

Command code for[unsubscribe](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser#unsubscribe(java.lang.String)).  

### COMMAND_CODE_SESSION_SET_RATING

```
const val COMMAND_CODE_SESSION_SET_RATING = 40010: Int
```

Command code for[setRating](https://developer.android.com/reference/kotlin/androidx/media3/session/MediaController#setRating(java.lang.String,androidx.media3.common.Rating)).  

## Public constructors

### SessionCommand

```
SessionCommand(@SessionCommand.CommandCode commandCode: Int)
```

Creates a predefined command.  

|                                                                                                          Parameters                                                                                                           |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------|
| `@`[SessionCommand.CommandCode](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand.CommandCode)` commandCode: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | A command code for a predefined command. |

### SessionCommand

```
SessionCommand(action: String!, extras: Bundle!)
```

Creates a custom command.  

|                                           Parameters                                           |
|------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `action: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | The action of this custom command.                                                                                                                                                                                    |
| `extras: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`!`          | An extra bundle for this custom command. This value is not used when the command is sent to a legacy`android.support.v4.media.session.MediaSessionCompat`or` android.support.v4.media.session.MediaControllerCompat`. |

## Public functions

### equals

```
fun equals(obj: Any?): Boolean
```

Checks the given session command for equality while ignoring extras.  

### fromBundle

```
@UnstableApi
java-static fun fromBundle(bundle: Bundle!): SessionCommand!
```

Restores a`SessionCommand`from a[Bundle](https://developer.android.com/reference/android/os/Bundle.html).  

### hashCode

```
fun hashCode(): Int
```  

### toBundle

```
@UnstableApi
fun toBundle(): Bundle!
```  

## Public properties

### commandCode

```
@SessionCommand.CommandCode
val commandCode: Int
```

The command code of a predefined command. It will be[COMMAND_CODE_CUSTOM](https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand#COMMAND_CODE_CUSTOM())for a custom command.  

### customAction

```
val customAction: String!
```

The action of a custom command. It will be an empty string for a predefined command.  

### customExtras

```
val customExtras: Bundle!
```

The extra bundle of a custom command. It will be[EMPTY](https://developer.android.com/reference/android/os/Bundle.html#EMPTY())for a predefined command.