public interface

MediaController.Listener

 androidx.media3.session.MediaController.Listener

Subclasses:

MediaBrowser.Listener

Overview

A listener for events and incoming commands from MediaSession.

The methods will be called from the application thread associated with the application looper of the controller.

Summary

Methods
public voidonAvailableSessionCommandsChanged(MediaController controller, SessionCommands commands)

Called when the available session commands are changed by session.

public <any>onCustomCommand(MediaController controller, SessionCommand command, Bundle args)

Called when the session sends a custom command through MediaSession.sendCustomCommand(MediaSession.ControllerInfo, SessionCommand, Bundle).

public voidonDisconnected(MediaController controller)

Called when the controller is disconnected from the session.

public <any>onSetCustomLayout(MediaController controller, java.util.List<CommandButton> layout)

Called when the session sets the custom layout through MediaSession.setCustomLayout(MediaSession.ControllerInfo, List).

Methods

public void onDisconnected(MediaController controller)

Called when the controller is disconnected from the session. The controller becomes unavailable afterwards and this listener won't be called anymore.

It will be also called after the MediaController.release(), so you can put clean up code here. You don't need to call MediaController.release() after this.

Parameters:

controller: The controller.

public <any> onSetCustomLayout(MediaController controller, java.util.List<CommandButton> layout)

Called when the session sets the custom layout through MediaSession.setCustomLayout(MediaSession.ControllerInfo, List).

Return a to reply with a SessionResult to the session asynchronously. You can also return a SessionResult directly by using Guava's .

The default implementation returns a of SessionResult.RESULT_ERROR_NOT_SUPPORTED.

Parameters:

controller: The controller.
layout: The ordered list of CommandButton.

Returns:

The result of handling the custom layout.

public void onAvailableSessionCommandsChanged(MediaController controller, SessionCommands commands)

Called when the available session commands are changed by session.

Parameters:

controller: The controller.
commands: The new available session commands.

public <any> onCustomCommand(MediaController controller, SessionCommand command, Bundle args)

Called when the session sends a custom command through MediaSession.sendCustomCommand(MediaSession.ControllerInfo, SessionCommand, Bundle).

Return a to reply with a SessionResult to the session asynchronously. You can also return a SessionResult directly by using Guava's .

The default implementation returns of SessionResult.RESULT_ERROR_NOT_SUPPORTED.

Parameters:

controller: The controller.
command: The custom command.
args: The additional arguments. May be empty.

Returns:

The result of handling the custom command.