MediaController.Listener


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 functions

Unit
onAvailableSessionCommandsChanged(
    controller: MediaController!,
    commands: SessionCommands!
)

Called when the available session commands are changed by session.

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

Called when the session sends a custom command through sendCustomCommand.

Unit
@UnstableApi
onCustomLayoutChanged(
    controller: MediaController!,
    layout: (Mutable)List<CommandButton!>!
)

Called when the custom layout changed.

Unit

Called when the controller is disconnected from the session.

Unit
@UnstableApi
onError(controller: MediaController!, sessionError: SessionError!)

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

Unit
onExtrasChanged(controller: MediaController!, extras: Bundle!)

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

Unit
@UnstableApi
onMediaButtonPreferencesChanged(
    controller: MediaController!,
    mediaButtonPreferences: (Mutable)List<CommandButton!>!
)

Called when the media button preferences changed.

Unit
@UnstableApi
onSessionActivityChanged(
    controller: MediaController!,
    sessionActivity: PendingIntent!
)

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

ListenableFuture<SessionResult!>!
onSetCustomLayout(
    controller: MediaController!,
    layout: (Mutable)List<CommandButton!>!
)

Called when the session sets the custom layout through setCustomLayout.

Public functions

onAvailableSessionCommandsChanged

fun onAvailableSessionCommandsChanged(
    controller: MediaController!,
    commands: SessionCommands!
): Unit

Called when the available session commands are changed by session.

Parameters
controller: MediaController!

The controller.

commands: SessionCommands!

The new available session commands.

onCustomCommand

fun onCustomCommand(
    controller: MediaController!,
    command: SessionCommand!,
    args: Bundle!
): ListenableFuture<SessionResult!>!

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
controller: MediaController!

The controller.

command: SessionCommand!

The custom command.

args: Bundle!

The additional arguments. May be empty.

Returns
ListenableFuture<SessionResult!>!

The result of handling the custom command.

onCustomLayoutChanged

@UnstableApi
fun onCustomLayoutChanged(
    controller: MediaController!,
    layout: (Mutable)List<CommandButton!>!
): Unit

Called when the custom layout changed.

This method will be deprecated, prefer to use onMediaButtonPreferencesChanged.

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: MediaController!

The controller.

layout: (Mutable)List<CommandButton!>!

The ordered list of command buttons.

onDisconnected

fun onDisconnected(controller: MediaController!): Unit

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
controller: MediaController!

The controller.

onError

@UnstableApi
fun onError(controller: MediaController!, sessionError: SessionError!): Unit

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
controller: MediaController!

The MediaController that received the error.

sessionError: SessionError!

The session error.

onExtrasChanged

fun onExtrasChanged(controller: MediaController!, extras: Bundle!): Unit

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

Parameters
controller: MediaController!

The controller.

extras: Bundle!

The session extras that have been set on the session.

onMediaButtonPreferencesChanged

@UnstableApi
fun onMediaButtonPreferencesChanged(
    controller: MediaController!,
    mediaButtonPreferences: (Mutable)List<CommandButton!>!
): Unit

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
controller: MediaController!

The controller.

mediaButtonPreferences: (Mutable)List<CommandButton!>!

The ordered list of command buttons.

onSessionActivityChanged

@UnstableApi
fun onSessionActivityChanged(
    controller: MediaController!,
    sessionActivity: PendingIntent!
): Unit

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

Parameters
controller: MediaController!

The controller.

sessionActivity: PendingIntent!

The pending intent to launch the session activity.

onSetCustomLayout

fun onSetCustomLayout(
    controller: MediaController!,
    layout: (Mutable)List<CommandButton!>!
): ListenableFuture<SessionResult!>!

Called when the session sets the custom layout through setCustomLayout.

This method will be deprecated. Use onCustomLayoutChanged 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 onCustomLayoutChanged 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 onCustomLayoutChanged is called, in which case the deprecated callback isn't called.