Android APIs
public static abstract class

MediaSessionCompat.Callback

extends Object
java.lang.Object
   ↳ android.support.v4.media.session.MediaSessionCompat.Callback

Class Overview

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

Summary

Public Constructors
MediaSessionCompat.Callback()
Public Methods
void onCommand(String command, Bundle extras, ResultReceiver cb)
Called when a controller has sent a custom command to this session.
void onCustomAction(String action, Bundle extras)
Called when a MediaControllerCompat wants a PlaybackStateCompat.CustomAction to be performed.
void onFastForward()
Override to handle requests to fast forward.
boolean onMediaButtonEvent(Intent mediaButtonEvent)
Override to handle media button events.
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.
void onPlayFromSearch(String query, Bundle extras)
Override to handle requests to begin playback from a search query.
void onPlayFromUri(Uri uri, Bundle extras)
Override to handle requests to play a specific media item represented by a URI.
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(RatingCompat 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 MediaSessionCompat.Callback ()

Public Methods

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

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 The command name.
extras 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)

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

Parameters
action The action that was originally sent in the PlaybackStateCompat.CustomAction.
extras Optional extras specified by the MediaControllerCompat.

public void onFastForward ()

Override to handle requests to fast forward.

public boolean onMediaButtonEvent (Intent mediaButtonEvent)

Override to handle media button events.

Parameters
mediaButtonEvent The media button event intent.
Returns
  • True if the event was handled, false otherwise.

public void onPause ()

Override to handle requests to pause playback.

public void onPlay ()

Override to handle requests to begin playback.

public void onPlayFromMediaId (String mediaId, Bundle extras)

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

public void onPlayFromSearch (String query, Bundle extras)

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 onPlayFromUri (Uri uri, Bundle extras)

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

public void onRewind ()

Override to handle requests to rewind.

public void onSeekTo (long pos)

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

Parameters
pos New position to move to, in milliseconds.

public void onSetRating (RatingCompat rating)

Override to handle the item being rated.

public void onSkipToNext ()

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

public void onSkipToPrevious ()

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

public void onSkipToQueueItem (long id)

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

public void onStop ()

Override to handle requests to stop playback.