MediaController2.ControllerCallback


public static abstract class MediaController2.ControllerCallback
extends Object

java.lang.Object
   ↳ android.media.MediaController2.ControllerCallback


This API is not generally intended for third party application developers. Use the AndroidX Media2 session Library for consistent behavior across all devices.

Interface for listening to change in activeness of the MediaSession2.

Summary

Public constructors

ControllerCallback()

Public methods

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

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

void onConnected(MediaController2 controller, Session2CommandGroup allowedCommands)

Called when the controller is successfully connected to the session.

void onDisconnected(MediaController2 controller)

Called when the session refuses the controller or the controller is disconnected from the session.

void onPlaybackActiveChanged(MediaController2 controller, boolean playbackActive)

Called when the session's playback activeness is changed.

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

Called when the connected session sent a session command.

Inherited methods

Public constructors

ControllerCallback

Added in API level 29
public ControllerCallback ()

Public methods

onCommandResult

Added in API level 29
public void onCommandResult (MediaController2 controller, 
                Object token, 
                Session2Command command, 
                Session2Command.Result result)

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

Parameters
controller MediaController2: the controller for this event This value cannot be null.

token Object: the token got from MediaController2.sendSessionCommand This value cannot be null.

command Session2Command: the session command This value cannot be null.

result Session2Command.Result: the result of the session command This value cannot be null.

onConnected

Added in API level 29
public void onConnected (MediaController2 controller, 
                Session2CommandGroup allowedCommands)

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

Parameters
controller MediaController2: the controller for this event This value cannot be null.

allowedCommands Session2CommandGroup: commands that's allowed by the session. This value cannot be null.

onDisconnected

Added in API level 29
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 MediaController2.close(), so you can put clean up code here. You don't need to call MediaController2.close() after this.

Parameters
controller MediaController2: the controller for this event This value cannot be null.

onPlaybackActiveChanged

Added in API level 29
public void onPlaybackActiveChanged (MediaController2 controller, 
                boolean playbackActive)

Called when the session's playback activeness is changed.

Parameters
controller MediaController2: the controller for this event This value cannot be null.

playbackActive boolean: true if the session's playback is active. false otherwise.

onSessionCommand

Added in API level 29
public Session2Command.Result onSessionCommand (MediaController2 controller, 
                Session2Command command, 
                Bundle args)

Called when the connected session sent a session command.

Parameters
controller MediaController2: the controller for this event This value cannot be null.

command Session2Command: the session command This value cannot be null.

args Bundle: optional arguments This value may be null.

Returns
Session2Command.Result the result for the session command. If null, RESULT_INFO_SKIPPED will be sent to the session.