Skip to content

Most visited

Recently visited

navigation

MediaSessionCompat.Callback

public static abstract class MediaSessionCompat.Callback
extends Object

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


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 onAddQueueItem(MediaDescriptionCompat description, int index)

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

void onAddQueueItem(MediaDescriptionCompat description)

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

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 onPrepare()

Override to handle requests to prepare playback.

void onPrepareFromMediaId(String mediaId, Bundle extras)

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

void onPrepareFromSearch(String query, Bundle extras)

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

void onPrepareFromUri(Uri uri, Bundle extras)

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

void onRemoveQueueItem(MediaDescriptionCompat description)

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

void onRemoveQueueItemAt(int index)

This method was deprecated in API level 26.0.0. onRemoveQueueItem(MediaDescriptionCompat) will be called instead.

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 onSetCaptioningEnabled(boolean enabled)

Override to handle requests to enable/disable captioning.

void onSetRating(RatingCompat rating)

Override to handle the item being rated.

void onSetRating(RatingCompat rating, Bundle extras)

Override to handle the item being rated.

void onSetRepeatMode(int repeatMode)

Override to handle the setting of the repeat mode.

void onSetShuffleMode(int shuffleMode)

Override to handle the setting of the shuffle mode.

void onSetShuffleModeEnabled(boolean enabled)

This method was deprecated in API level 26.0.0. Use onSetShuffleMode(int) instead.

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.

Inherited methods

From class java.lang.Object

Public constructors

MediaSessionCompat.Callback

added in version 22.0.0
MediaSessionCompat.Callback ()

Public methods

onAddQueueItem

added in version 25.3.0
void onAddQueueItem (MediaDescriptionCompat description, 
                int index)

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

Parameters
description MediaDescriptionCompat: The MediaDescriptionCompat for creating the MediaSessionCompat.QueueItem to be inserted.

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

onAddQueueItem

added in version 25.3.0
void onAddQueueItem (MediaDescriptionCompat description)

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

Parameters
description MediaDescriptionCompat: The MediaDescriptionCompat for creating the MediaSessionCompat.QueueItem to be inserted.

onCommand

added in version 22.0.0
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 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 version 22.0.0
void onCustomAction (String action, 
                Bundle extras)

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.

See also:

onFastForward

added in version 22.0.0
void onFastForward ()

Override to handle requests to fast forward.

onMediaButtonEvent

added in version 22.0.0
boolean onMediaButtonEvent (Intent mediaButtonEvent)

Override to handle media button events.

The double tap of KEYCODE_MEDIA_PLAY_PAUSE or KEYCODE_HEADSETHOOK will call the onSkipToNext() by default.

Parameters
mediaButtonEvent Intent: The media button event intent.

Returns
boolean True if the event was handled, false otherwise.

onPause

added in version 22.0.0
void onPause ()

Override to handle requests to pause playback.

onPlay

added in version 22.0.0
void onPlay ()

Override to handle requests to begin playback.

onPlayFromMediaId

added in version 22.0.0
void onPlayFromMediaId (String mediaId, 
                Bundle extras)

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

Parameters
mediaId String

extras Bundle

onPlayFromSearch

added in version 22.0.0
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.

Parameters
query String

extras Bundle

onPlayFromUri

added in version 23.0.0
void onPlayFromUri (Uri uri, 
                Bundle extras)

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

Parameters
uri Uri

extras Bundle

onPrepare

added in version 24.0.0
void onPrepare ()

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

onPrepareFromMediaId

added in version 24.0.0
void onPrepareFromMediaId (String mediaId, 
                Bundle extras)

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

Parameters
mediaId String

extras Bundle

onPrepareFromSearch

added in version 24.0.0
void onPrepareFromSearch (String query, 
                Bundle extras)

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(String, Bundle) to handle requests for starting playback.

Parameters
query String

extras Bundle

onPrepareFromUri

added in version 24.0.0
void onPrepareFromUri (Uri uri, 
                Bundle extras)

Override to handle requests to prepare a specific media item represented by a URI. Override onPlayFromUri(Uri, Bundle) to handle requests for starting playback.

Parameters
uri Uri

extras Bundle

onRemoveQueueItem

added in version 25.3.0
void onRemoveQueueItem (MediaDescriptionCompat description)

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

Parameters
description MediaDescriptionCompat: The MediaDescriptionCompat for denoting the MediaSessionCompat.QueueItem to be removed.

onRemoveQueueItemAt

added in version 25.3.0
void onRemoveQueueItemAt (int index)

This method was deprecated in API level 26.0.0.
onRemoveQueueItem(MediaDescriptionCompat) will be called instead.

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

Parameters
index int: The index of the element to be removed.

onRewind

added in version 22.0.0
void onRewind ()

Override to handle requests to rewind.

onSeekTo

added in version 22.0.0
void onSeekTo (long pos)

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 version 25.4.0
void onSetCaptioningEnabled (boolean enabled)

Override to handle requests to enable/disable captioning.

Parameters
enabled boolean: true to enable captioning, false to disable.

onSetRating

added in version 22.0.0
void onSetRating (RatingCompat rating)

Override to handle the item being rated.

Parameters
rating RatingCompat: The rating being set.

onSetRating

added in version 26.0.0
void onSetRating (RatingCompat rating, 
                Bundle extras)

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 version 25.3.0
void onSetRepeatMode (int repeatMode)

Override to handle the setting of the repeat mode.

You should call setRepeatMode(int) 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 version 26.0.0
void onSetShuffleMode (int shuffleMode)

Override to handle the setting of the shuffle mode.

You should call setShuffleMode(int) 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

onSetShuffleModeEnabled

added in version 25.3.0
void onSetShuffleModeEnabled (boolean enabled)

This method was deprecated in API level 26.0.0.
Use onSetShuffleMode(int) instead.

Override to handle the setting of the shuffle mode.

You should call setShuffleModeEnabled(boolean) before the end of this method in order to notify the change to the MediaControllerCompat, or isShuffleModeEnabled() could return an invalid value.

Parameters
enabled boolean: true when the shuffle mode is enabled, false otherwise.

onSkipToNext

added in version 22.0.0
void onSkipToNext ()

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

onSkipToPrevious

added in version 22.0.0
void onSkipToPrevious ()

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

onSkipToQueueItem

added in version 22.0.0
void onSkipToQueueItem (long id)

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

Parameters
id long

onStop

added in version 22.0.0
void onStop ()

Override to handle requests to stop playback.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.