Android APIs
public static abstract class

MediaSession.Callback

extends Object
java.lang.Object
   ↳ android.media.session.MediaSession.Callback

Class Overview

Receives media buttons, transport controls, and commands from controllers and the system. A callback may be set using setCallback(MediaSession.Callback).

Summary

Public Constructors
MediaSession.Callback()
Public Methods
void onCommand(String command, Bundle args, ResultReceiver cb)
Called when a controller has sent a command to this session.
void onCustomAction(String action, Bundle extras)
Called when a MediaController wants a PlaybackState.CustomAction to be performed.
void onFastForward()
Override to handle requests to fast forward.
boolean onMediaButtonEvent(Intent mediaButtonIntent)
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.
void onPause()
Override to handle requests to pause playback.
void onPlay()
Override to handle requests to begin playback.
void onPlayFromMediaId(String mediaId, Bundle extras)
Override to handle requests to play a specific mediaId that was provided by your app's MediaBrowserService.
void onPlayFromSearch(String query, Bundle extras)
Override to handle requests to begin playback from a search query.
void onRewind()
Override to handle requests to rewind.
void onSeekTo(long pos)
Override to handle requests to seek to a specific position in ms.
void onSetRating(Rating rating)
Override to handle the item being rated.
void onSkipToNext()
Override to handle requests to skip to the next media item.
void onSkipToPrevious()
Override to handle requests to skip to the previous media item.
void onSkipToQueueItem(long id)
Override to handle requests to play an item with a given id from the play queue.
void onStop()
Override to handle requests to stop playback.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public MediaSession.Callback ()

Added in API level 21

Public Methods

public void onCommand (String command, Bundle args, ResultReceiver cb)

Added in API level 21

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 The command name.
args Optional parameters for the command, may be null.
cb A result receiver to which a result may be sent by the command, may be null.

public void onCustomAction (String action, Bundle extras)

Added in API level 21

Called when a MediaController wants a PlaybackState.CustomAction to be performed.

Parameters
action The action that was originally sent in the PlaybackState.CustomAction.
extras Optional extras specified by the MediaController.

public void onFastForward ()

Added in API level 21

Override to handle requests to fast forward.

public boolean onMediaButtonEvent (Intent mediaButtonIntent)

Added in API level 21

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 ACTION_MEDIA_BUTTON with a KeyEvent in EXTRA_KEY_EVENT

Parameters
mediaButtonIntent an intent containing the KeyEvent as an extra
Returns
  • True if the event was handled, false otherwise.

public void onPause ()

Added in API level 21

Override to handle requests to pause playback.

public void onPlay ()

Added in API level 21

Override to handle requests to begin playback.

public void onPlayFromMediaId (String mediaId, Bundle extras)

Added in API level 21

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

public void onPlayFromSearch (String query, Bundle extras)

Added in API level 21

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.

public void onRewind ()

Added in API level 21

Override to handle requests to rewind.

public void onSeekTo (long pos)

Added in API level 21

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

Parameters
pos New position to move to, in milliseconds.

public void onSetRating (Rating rating)

Added in API level 21

Override to handle the item being rated.

public void onSkipToNext ()

Added in API level 21

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

public void onSkipToPrevious ()

Added in API level 21

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

public void onSkipToQueueItem (long id)

Added in API level 21

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

public void onStop ()

Added in API level 21

Override to handle requests to stop playback.