Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/media/MediaController2.ControllerCallback#pubctors) \| [Methods](https://developer.android.com/reference/android/media/MediaController2.ControllerCallback#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/MediaController2.ControllerCallback#inhmethods)

# MediaController2.ControllerCallback

*** ** * ** ***

` public static abstract class MediaController2.ControllerCallback `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.media.MediaController2.ControllerCallback |

<br />

*** ** * ** ***

<br />

**This class was deprecated in API level 37.**   

Use the Media3 support library's `androidx.media3.session.MediaController` instead.

This API is not generally intended for third party application developers. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Media3 session Library](https://developer.android.com/media/media3/session/control-playback) for consistent behavior across all devices.

Interface for listening to change in activeness of the `https://developer.android.com/reference/android/media/MediaSession2`.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/media/MediaController2.ControllerCallback#ControllerCallback()() ` |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/media/MediaController2.ControllerCallback#onCommandResult(android.media.MediaController2,%20java.lang.Object,%20android.media.Session2Command,%20android.media.Session2Command.Result)(https://developer.android.com/reference/android/media/MediaController2 controller, https://developer.android.com/reference/java/lang/Object token, https://developer.android.com/reference/android/media/Session2Command command, https://developer.android.com/reference/android/media/Session2Command.Result result) ` Called when the command sent to the connected session is finished. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaController2.ControllerCallback#onConnected(android.media.MediaController2,%20android.media.Session2CommandGroup)(https://developer.android.com/reference/android/media/MediaController2 controller, https://developer.android.com/reference/android/media/Session2CommandGroup allowedCommands) ` Called when the controller is successfully connected to the session. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaController2.ControllerCallback#onDisconnected(android.media.MediaController2)(https://developer.android.com/reference/android/media/MediaController2 controller) ` Called when the session refuses the controller or the controller is disconnected from the session. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaController2.ControllerCallback#onPlaybackActiveChanged(android.media.MediaController2,%20boolean)(https://developer.android.com/reference/android/media/MediaController2 controller, boolean playbackActive) ` Called when the session's playback activeness is changed. |
| ` https://developer.android.com/reference/android/media/Session2Command.Result` | ` https://developer.android.com/reference/android/media/MediaController2.ControllerCallback#onSessionCommand(android.media.MediaController2,%20android.media.Session2Command,%20android.os.Bundle)(https://developer.android.com/reference/android/media/MediaController2 controller, https://developer.android.com/reference/android/media/Session2Command command, https://developer.android.com/reference/android/os/Bundle args) ` Called when the connected session sent a session command. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public constructors

### ControllerCallback

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ControllerCallback ()
```

<br />

<br />

## Public methods

### onCommandResult

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onCommandResult (MediaController2 controller, 
                Object token, 
                Session2Command command, 
                Session2Command.Result result)
```

Called when the command sent to the connected session is finished.

<br />

| Parameters ||
|---|---|
| `controller` | `MediaController2`: the controller for this event. This value cannot be `null`. <br /> |
| `token` | `Object`: the token got from `https://developer.android.com/reference/android/media/MediaController2#sendSessionCommand(android.media.Session2Command,%20android.os.Bundle)` This value cannot be `null`. <br /> |
| `command` | `Session2Command`: the session command. This value cannot be `null`. <br /> |
| `result` | `Session2Command.Result`: the result of the session command. This value cannot be `null`. <br /> |

### onConnected

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onConnected (MediaController2 controller, 
                Session2CommandGroup allowedCommands)
```

Called when the controller is successfully connected to the session. The controller becomes available afterwards.

<br />

| Parameters ||
|---|---|
| `controller` | `MediaController2`: the controller for this event. This value cannot be `null`. <br /> |
| `allowedCommands` | `Session2CommandGroup`: commands that's allowed by the session. This value cannot be `null`. <br /> |

### onDisconnected

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onDisconnected (MediaController2 controller)
```

Called when the session refuses the controller or the controller is disconnected from the session. The controller becomes unavailable afterwards and the callback wouldn't be called.

It will be also called after the `https://developer.android.com/reference/android/media/MediaController2#close()`, so you can put clean up code here. You don't need to call `https://developer.android.com/reference/android/media/MediaController2#close()` after this.

<br />

| Parameters ||
|---|---|
| `controller` | `MediaController2`: the controller for this event. This value cannot be `null`. <br /> |

### onPlaybackActiveChanged

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onPlaybackActiveChanged (MediaController2 controller, 
                boolean playbackActive)
```

Called when the session's playback activeness is changed.

<br />

| Parameters ||
|---|---|
| `controller` | `MediaController2`: the controller for this event. This value cannot be `null`. <br /> |
| `playbackActive` | `boolean`: `true` if the session's playback is active. `false` otherwise. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/MediaController2#isPlaybackActive()`

### onSessionCommand

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Session2Command.Result onSessionCommand (MediaController2 controller, 
                Session2Command command, 
                Bundle args)
```

Called when the connected session sent a session command.

<br />

| Parameters ||
|---|---|
| `controller` | `MediaController2`: the controller for this event. This value cannot be `null`. <br /> |
| `command` | `Session2Command`: the session command. This value cannot be `null`. <br /> |
| `args` | `Bundle`: optional arguments. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/media/Session2Command.Result` | the result for the session command. If `null`, RESULT_INFO_SKIPPED will be sent to the session. <br /> |