MediaSessionCompat.Callback


abstract class MediaSessionCompat.Callback


Receives transport controls, media buttons, and commands from controllers and the system. The callback may be set using setCallback.

Don't reuse the callback among the sessions. Callbacks keep internal reference to the session when it's set, so it may misbehave.

Summary

Public constructors

Public functions

Unit

Called when a MediaControllerCompat wants to add a QueueItem with the given description at the end of the play queue.

Unit
onAddQueueItem(description: MediaDescriptionCompat!, index: Int)

Called when a MediaControllerCompat wants to add a QueueItem with the given description at the specified position in the play queue.

Unit
onCommand(command: String!, extras: Bundle!, cb: ResultReceiver!)

Called when a controller has sent a custom command to this session.

Unit
onCustomAction(action: String!, extras: Bundle!)

Called when a MediaControllerCompat wants a PlaybackStateCompat.CustomAction to be performed.

Unit

Override to handle requests to fast forward.

Boolean
onMediaButtonEvent(mediaButtonEvent: Intent!)

Override to handle media button events.

Unit

Override to handle requests to pause playback.

Unit

Override to handle requests to begin playback.

Unit
onPlayFromMediaId(mediaId: String!, extras: Bundle!)

Override to handle requests to play a specific mediaId that was provided by your app.

Unit
onPlayFromSearch(query: String!, extras: Bundle!)

Override to handle requests to begin playback from a search query.

Unit
onPlayFromUri(uri: Uri!, extras: Bundle!)

Override to handle requests to play a specific media item represented by a URI.

Unit

Override to handle requests to prepare playback.

Unit
onPrepareFromMediaId(mediaId: String!, extras: Bundle!)

Override to handle requests to prepare for playing a specific mediaId that was provided by your app.

Unit
onPrepareFromSearch(query: String!, extras: Bundle!)

Override to handle requests to prepare playback from a search query.

Unit
onPrepareFromUri(uri: Uri!, extras: Bundle!)

Override to handle requests to prepare a specific media item represented by a URI.

Unit

Called when a MediaControllerCompat wants to remove the first occurrence of the specified QueueItem with the given description in the play queue.

Unit

This function is deprecated.

onRemoveQueueItem will be called instead.

Unit

Override to handle requests to rewind.

Unit
onSeekTo(pos: Long)

Override to handle requests to seek to a specific position in ms.

Unit

Override to handle requests to enable/disable captioning.

Unit

Override to handle the playback speed change.

Unit

Override to handle the item being rated.

Unit
onSetRating(rating: RatingCompat!, extras: Bundle!)

Override to handle the item being rated.

Unit
onSetRepeatMode(repeatMode: Int)

Override to handle the setting of the repeat mode.

Unit
onSetShuffleMode(shuffleMode: Int)

Override to handle the setting of the shuffle mode.

Unit

Override to handle requests to skip to the next media item.

Unit

Override to handle requests to skip to the previous media item.

Unit

Override to handle requests to play an item with a given id from the play queue.

Unit

Override to handle requests to stop playback.

Public constructors

Callback

Added in 1.1.0
Callback()

Public functions

onAddQueueItem

Added in 1.1.0
fun onAddQueueItem(description: MediaDescriptionCompat!): Unit

Called when a MediaControllerCompat wants to add a QueueItem with the given description at the end of the play queue.

Parameters
description: MediaDescriptionCompat!

The MediaDescriptionCompat for creating the QueueItem to be inserted.

onAddQueueItem

Added in 1.1.0
fun onAddQueueItem(description: MediaDescriptionCompat!, index: Int): Unit

Called when a MediaControllerCompat wants to add a QueueItem with the given description at the specified position in the play queue.

Parameters
description: MediaDescriptionCompat!

The MediaDescriptionCompat for creating the QueueItem to be inserted.

index: Int

The index at which the created QueueItem is to be inserted.

onCommand

Added in 1.1.0
fun onCommand(command: String!, extras: Bundle!, cb: ResultReceiver!): Unit

Called when a controller has sent a custom command to this session. The owner of the session may handle custom commands but is not required to.

Parameters
command: String!

The command name.

extras: Bundle!

Optional parameters for the command, may be null.

cb: ResultReceiver!

A result receiver to which a result may be sent by the command, may be null.

onCustomAction

Added in 1.1.0
fun onCustomAction(action: String!, extras: Bundle!): Unit

Called when a MediaControllerCompat wants a PlaybackStateCompat.CustomAction to be performed.

Parameters
action: String!

The action that was originally sent in the PlaybackStateCompat.CustomAction.

extras: Bundle!

Optional extras specified by the MediaControllerCompat.

onFastForward

Added in 1.1.0
fun onFastForward(): Unit

Override to handle requests to fast forward.

onMediaButtonEvent

Added in 1.1.0
fun onMediaButtonEvent(mediaButtonEvent: Intent!): Boolean

Override to handle media button events.

The double tap of KEYCODE_MEDIA_PLAY_PAUSE or KEYCODE_HEADSETHOOK will call the onSkipToNext by default. If the current SDK level is 27 or higher, the default double tap handling is done by framework so this method would do nothing for it.

Parameters
mediaButtonEvent: Intent!

The media button event intent.

Returns
Boolean

True if the event was handled, false otherwise.

onPause

Added in 1.1.0
fun onPause(): Unit

Override to handle requests to pause playback.

onPlay

Added in 1.1.0
fun onPlay(): Unit

Override to handle requests to begin playback.

onPlayFromMediaId

Added in 1.1.0
fun onPlayFromMediaId(mediaId: String!, extras: Bundle!): Unit

Override to handle requests to play a specific mediaId that was provided by your app.

onPlayFromSearch

Added in 1.1.0
fun onPlayFromSearch(query: String!, extras: Bundle!): Unit

Override to handle requests to begin playback from a search query. An empty query indicates that the app may play any music. The implementation should attempt to make a smart choice about what to play.

onPlayFromUri

Added in 1.1.0
fun onPlayFromUri(uri: Uri!, extras: Bundle!): Unit

Override to handle requests to play a specific media item represented by a URI.

onPrepare

Added in 1.1.0
fun onPrepare(): Unit

Override to handle requests to prepare playback. Override onPlay to handle requests for starting playback.

onPrepareFromMediaId

Added in 1.1.0
fun onPrepareFromMediaId(mediaId: String!, extras: Bundle!): Unit

Override to handle requests to prepare for playing a specific mediaId that was provided by your app. Override onPlayFromMediaId to handle requests for starting playback.

onPrepareFromSearch

Added in 1.1.0
fun onPrepareFromSearch(query: String!, extras: Bundle!): Unit

Override to handle requests to prepare playback from a search query. An empty query indicates that the app may prepare any music. The implementation should attempt to make a smart choice about what to play. Override onPlayFromSearch to handle requests for starting playback.

onPrepareFromUri

Added in 1.1.0
fun onPrepareFromUri(uri: Uri!, extras: Bundle!): Unit

Override to handle requests to prepare a specific media item represented by a URI. Override onPlayFromUri to handle requests for starting playback.

onRemoveQueueItem

Added in 1.1.0
fun onRemoveQueueItem(description: MediaDescriptionCompat!): Unit

Called when a MediaControllerCompat wants to remove the first occurrence of the specified QueueItem with the given description in the play queue.

Parameters
description: MediaDescriptionCompat!

The MediaDescriptionCompat for denoting the QueueItem to be removed.

onRemoveQueueItemAt

Added in 1.1.0
Deprecated in 1.1.0
fun onRemoveQueueItemAt(index: Int): Unit

Called when a MediaControllerCompat wants to remove a QueueItem at the specified position in the play queue.

Parameters
index: Int

The index of the element to be removed.

onRewind

Added in 1.1.0
fun onRewind(): Unit

Override to handle requests to rewind.

onSeekTo

Added in 1.1.0
fun onSeekTo(pos: Long): Unit

Override to handle requests to seek to a specific position in ms.

Parameters
pos: Long

New position to move to, in milliseconds.

onSetCaptioningEnabled

Added in 1.1.0
fun onSetCaptioningEnabled(enabled: Boolean): Unit

Override to handle requests to enable/disable captioning.

Parameters
enabled: Boolean

true to enable captioning, false to disable.

onSetPlaybackSpeed

Added in 1.2.0
fun onSetPlaybackSpeed(speed: Float): Unit

Override to handle the playback speed change. To update the new playback speed, create a new PlaybackStateCompat by using setState, and set it with setPlaybackState.

A value of 1.0f is the default playback value, and a negative value indicates reverse playback. The speed will not be equal to zero.

Parameters
speed: Float

the playback speed

onSetRating

Added in 1.1.0
fun onSetRating(rating: RatingCompat!): Unit

Override to handle the item being rated.

Parameters
rating: RatingCompat!

The rating being set.

onSetRating

Added in 1.1.0
fun onSetRating(rating: RatingCompat!, extras: Bundle!): Unit

Override to handle the item being rated.

Parameters
rating: RatingCompat!

The rating being set.

extras: Bundle!

The extras can include information about the media item being rated.

onSetRepeatMode

Added in 1.1.0
fun onSetRepeatMode(repeatMode: Int): Unit

Override to handle the setting of the repeat mode.

You should call setRepeatMode before end of this method in order to notify the change to the MediaControllerCompat, or getRepeatMode could return an invalid value.

Parameters
repeatMode: Int

The repeat mode which is one of followings: REPEAT_MODE_NONE, REPEAT_MODE_ONE, REPEAT_MODE_ALL, REPEAT_MODE_GROUP

onSetShuffleMode

Added in 1.1.0
fun onSetShuffleMode(shuffleMode: Int): Unit

Override to handle the setting of the shuffle mode.

You should call setShuffleMode before the end of this method in order to notify the change to the MediaControllerCompat, or getShuffleMode could return an invalid value.

Parameters
shuffleMode: Int

The shuffle mode which is one of followings: SHUFFLE_MODE_NONE, SHUFFLE_MODE_ALL, SHUFFLE_MODE_GROUP

onSkipToNext

Added in 1.1.0
fun onSkipToNext(): Unit

Override to handle requests to skip to the next media item.

onSkipToPrevious

Added in 1.1.0
fun onSkipToPrevious(): Unit

Override to handle requests to skip to the previous media item.

onSkipToQueueItem

Added in 1.1.0
fun onSkipToQueueItem(id: Long): Unit

Override to handle requests to play an item with a given id from the play queue.

onStop

Added in 1.1.0
fun onStop(): Unit

Override to handle requests to stop playback.