MediaController.Listener


public interface MediaController.Listener

Known direct subclasses
MediaBrowser.Listener

A listener for events from MediaLibraryService.


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

Public methods

default void

Called when the available session commands are changed by session.

default ListenableFuture<SessionResult>
onCustomCommand(
    MediaController controller,
    SessionCommand command,
    Bundle args
)

Called when the session sends a custom command through sendCustomCommand.

default void
onCustomLayoutChanged(
    MediaController controller,
    List<CommandButton> layout
)

This method is deprecated.

Use onMediaButtonPreferencesChanged instead.

default void

Called when the controller is disconnected from the session.

default void
@UnstableApi
onError(MediaController controller, SessionError sessionError)

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

default void
onExtrasChanged(MediaController controller, Bundle extras)

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

default void
onMediaButtonPreferencesChanged(
    MediaController controller,
    List<CommandButton> mediaButtonPreferences
)

Called when the media button preferences changed.

default void
@UnstableApi
onSessionActivityChanged(
    MediaController controller,
    @Nullable PendingIntent sessionActivity
)

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

default ListenableFuture<SessionResult>
onSetCustomLayout(
    MediaController controller,
    List<CommandButton> layout
)

This method is deprecated.

Use onMediaButtonPreferencesChanged instead.

Public methods

onAvailableSessionCommandsChanged

default void onAvailableSessionCommandsChanged(
    MediaController controller,
    SessionCommands commands
)

Called when the available session commands are changed by session.

Parameters
MediaController controller

The controller.

SessionCommands commands

The new available session commands.

onCustomCommand

default ListenableFuture<SessionResult> onCustomCommand(
    MediaController controller,
    SessionCommand command,
    Bundle args
)

Called when the session sends a custom command through sendCustomCommand.

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

The default implementation returns ListenableFuture of ERROR_NOT_SUPPORTED.

Parameters
MediaController controller

The controller.

SessionCommand command

The custom command.

Bundle args

The additional arguments. May be empty.

Returns
ListenableFuture<SessionResult>

The result of handling the custom command.

onCustomLayoutChanged

default void onCustomLayoutChanged(
    MediaController controller,
    List<CommandButton> layout
)

onDisconnected

default 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 release, so you can put clean up code here. You don't need to call release after this.

Parameters
MediaController controller

The controller.

onError

@UnstableApi
default 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 onPlaybackStateChanged 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 onPlayerError and onPlayerErrorChanged of listeners registered on the controller.

Parameters
MediaController controller

The MediaController that received the error.

SessionError sessionError

The session error.

onExtrasChanged

default void onExtrasChanged(MediaController controller, Bundle extras)

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

Parameters
MediaController controller

The controller.

Bundle extras

The session extras that have been set on the session.

onMediaButtonPreferencesChanged

default void onMediaButtonPreferencesChanged(
    MediaController controller,
    List<CommandButton> mediaButtonPreferences
)

Called when the media button preferences changed.

The media button preferences can change when either the session changes the media button preferences, or when the session changes the available commands for a controller that affect whether buttons of the media button preferences 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
MediaController controller

The controller.

List<CommandButton> mediaButtonPreferences

The ordered list of command buttons.

onSessionActivityChanged

@UnstableApi
default void onSessionActivityChanged(
    MediaController controller,
    @Nullable PendingIntent sessionActivity
)

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

Parameters
MediaController controller

The controller.

@Nullable PendingIntent sessionActivity

The pending intent to launch the session activity.

onSetCustomLayout

default ListenableFuture<SessionResult> onSetCustomLayout(
    MediaController controller,
    List<CommandButton> layout
)