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 voidonCustomLayoutChanged(MediaController controller, java.util.List<CommandButton> layout)

Called when the custom layout changed.

public voidonDisconnected(MediaController controller)

Called when the controller is disconnected from the session.

public voidonError(MediaController controller, SessionError sessionError)

Called when an non-fatal error sent by the session is received.

public voidonExtrasChanged(MediaController controller, Bundle extras)

Called when the session extras are set on the session side.

public voidonSessionActivityChanged(MediaController controller, PendingIntent sessionActivity)

Called when the PendingIntent to launch the session activity has been changed on the session side.

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).

This method will be deprecated. Use MediaController.Listener.onCustomLayoutChanged(MediaController, List) instead.

There is a slight difference in behaviour. This to be deprecated method may be consecutively called with an unchanged custom layout passed into it, in which case the new MediaController.Listener.onCustomLayoutChanged(MediaController, List) isn't called again for equal arguments.

Further, when the available commands of a controller change in a way that affect whether buttons of the custom layout are enabled or disabled, the new callback MediaController.Listener.onCustomLayoutChanged(MediaController, List) is called, in which case the deprecated callback isn't called.

public void onCustomLayoutChanged(MediaController controller, java.util.List<CommandButton> layout)

Called when the custom layout changed.

The custom layout can change when either the session changes the custom layout, or when the session changes the available commands for a controller that affect whether buttons of the custom layout are enabled or disabled.

Note that the enabled flag is set to false if the available commands do not allow to use a button.

Parameters:

controller: The controller.
layout: The ordered list of command buttons.

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 SessionError.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.

public void onExtrasChanged(MediaController controller, Bundle extras)

Called when the session extras are set on the session side.

Parameters:

controller: The controller.
extras: The session extras that have been set on the session.

public void onSessionActivityChanged(MediaController controller, PendingIntent sessionActivity)

Called when the PendingIntent to launch the session activity has been changed on the session side.

Parameters:

controller: The controller.
sessionActivity: The pending intent to launch the session activity.

public void onError(MediaController controller, SessionError sessionError)

Called when an non-fatal error sent by the session is received.

When connected to a legacy or platform session, this callback is called when is called with an error code and an error message while the playback state is different to state error.

Fatal playback errors are reported to and of listeners registered on the controller.

Parameters:

controller: The MediaController that received the error.
sessionError: The session error.