Callback
abstract class Callback
| kotlin.Any | |
| ↳ | android.media.session.MediaSession.Callback | 
Receives media buttons, transport controls, and commands from controllers and the system. A callback may be set using #setCallback.
Summary
| Public constructors | |
|---|---|
| Callback() | |
| Public methods | |
|---|---|
| open Unit | onCommand(command: String, args: Bundle?, cb: ResultReceiver?)Called when a controller has sent a command to this session. | 
| open Unit | onCustomAction(action: String, extras: Bundle?)Called when a  | 
| open Unit | Override to handle requests to fast forward. | 
| open Boolean | onMediaButtonEvent(mediaButtonIntent: Intent)Called when a media button is pressed and this session has the highest priority or a controller sends a media button event to the session. | 
| open Unit | onPause()Override to handle requests to pause playback. | 
| open Unit | onPlay()Override to handle requests to begin playback. | 
| open Unit | onPlayFromMediaId(mediaId: String!, extras: Bundle!)Override to handle requests to play a specific mediaId that was provided by your app's  | 
| open Unit | onPlayFromSearch(query: String!, extras: Bundle!)Override to handle requests to begin playback from a search query. | 
| open Unit | onPlayFromUri(uri: Uri!, extras: Bundle!)Override to handle requests to play a specific media item represented by a URI. | 
| open Unit | Override to handle requests to prepare playback. | 
| open Unit | onPrepareFromMediaId(mediaId: String!, extras: Bundle!)Override to handle requests to prepare for playing a specific mediaId that was provided by your app's  | 
| open Unit | onPrepareFromSearch(query: String!, extras: Bundle!)Override to handle requests to prepare playback from a search query. | 
| open Unit | onPrepareFromUri(uri: Uri!, extras: Bundle!)Override to handle requests to prepare a specific media item represented by a URI. | 
| open Unit | onRewind()Override to handle requests to rewind. | 
| open Unit | Override to handle requests to seek to a specific position in ms. | 
| open Unit | onSetPlaybackSpeed(speed: Float)Override to handle the playback speed change. | 
| open Unit | onSetRating(rating: Rating)Override to handle the item being rated. | 
| open Unit | Override to handle requests to skip to the next media item. | 
| open Unit | Override to handle requests to skip to the previous media item. | 
| open Unit | onSkipToQueueItem(id: Long)Override to handle requests to play an item with a given id from the play queue. | 
| open Unit | onStop()Override to handle requests to stop playback. | 
Public constructors
Public methods
onCommand
open fun onCommand(
command: String,
args: Bundle?,
cb: ResultReceiver?
): Unit
Called when a controller has sent a command to this session. The owner of the session may handle custom commands but is not required to.
| Parameters | |
|---|---|
| command | String: The command name. This value cannot be null. | 
| args | 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
open fun onCustomAction(
action: String,
extras: Bundle?
): Unit
Called when a MediaController wants a PlaybackState.CustomAction to be performed.
| Parameters | |
|---|---|
| action | String: The action that was originally sent in the PlaybackState.CustomAction. This value cannot benull. | 
| extras | Bundle?: Optional extras specified by the MediaController. This value may benull. | 
onFastForward
open fun onFastForward(): Unit
Override to handle requests to fast forward.
onMediaButtonEvent
open fun onMediaButtonEvent(mediaButtonIntent: Intent): Boolean
Called when a media button is pressed and this session has the highest priority or a controller sends a media button event to the session. The default behavior will call the relevant method if the action for it was set.
 The intent will be of type Intent.ACTION_MEDIA_BUTTON with a KeyEvent in Intent.EXTRA_KEY_EVENT
| Parameters | |
|---|---|
| mediaButtonIntent | Intent: an intent containing the KeyEvent as an extra This value cannot be null. | 
| Return | |
|---|---|
| Boolean | True if the event was handled, false otherwise. | 
onPause
open fun onPause(): Unit
Override to handle requests to pause playback.
onPlayFromMediaId
open fun onPlayFromMediaId(
mediaId: String!,
extras: Bundle!
): Unit
Override to handle requests to play a specific mediaId that was provided by your app's MediaBrowserService.
onPlayFromSearch
open 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
open fun onPlayFromUri(
uri: Uri!,
extras: Bundle!
): Unit
Override to handle requests to play a specific media item represented by a URI.
onPrepare
open fun onPrepare(): Unit
Override to handle requests to prepare playback. During the preparation, a session should not hold audio focus in order to allow other sessions play seamlessly. The state of playback should be updated to PlaybackState.STATE_PAUSED after the preparation is done.
onPrepareFromMediaId
open fun onPrepareFromMediaId(
mediaId: String!,
extras: Bundle!
): Unit
Override to handle requests to prepare for playing a specific mediaId that was provided by your app's MediaBrowserService. During the preparation, a session should not hold audio focus in order to allow other sessions play seamlessly. The state of playback should be updated to PlaybackState.STATE_PAUSED after the preparation is done. The playback of the prepared content should start in the implementation of onPlay. Override onPlayFromMediaId to handle requests for starting playback without preparation.
onPrepareFromSearch
open 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. During the preparation, a session should not hold audio focus in order to allow other sessions play seamlessly. The state of playback should be updated to PlaybackState.STATE_PAUSED after the preparation is done. The playback of the prepared content should start in the implementation of onPlay. Override onPlayFromSearch to handle requests for starting playback without preparation.
onPrepareFromUri
open fun onPrepareFromUri(
uri: Uri!,
extras: Bundle!
): Unit
Override to handle requests to prepare a specific media item represented by a URI. During the preparation, a session should not hold audio focus in order to allow other sessions play seamlessly. The state of playback should be updated to PlaybackState.STATE_PAUSED after the preparation is done. The playback of the prepared content should start in the implementation of onPlay. Override onPlayFromUri to handle requests for starting playback without preparation.
onSeekTo
open 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. | 
onSetPlaybackSpeed
open fun onSetPlaybackSpeed(speed: Float): Unit
Override to handle the playback speed change. To update the new playback speed, create a new PlaybackState by using android.media.session.PlaybackState.Builder#setState(int,long,float), and set it with setPlaybackState(android.media.session.PlaybackState). 
 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
open fun onSetRating(rating: Rating): Unit
Override to handle the item being rated.
| Parameters | |
|---|---|
| rating | Rating: This value cannot be null. | 
onSkipToNext
open fun onSkipToNext(): Unit
Override to handle requests to skip to the next media item.
onSkipToPrevious
open fun onSkipToPrevious(): Unit
Override to handle requests to skip to the previous media item.
onSkipToQueueItem
open fun onSkipToQueueItem(id: Long): Unit
Override to handle requests to play an item with a given id from the play queue.
