# MediaSessionCompat

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:support-media-compat:28.0.0-alpha1  
Summary:[Nested Classes](https://developer.android.com/reference/android/support/v4-media-session/MediaSessionCompat#nestedclasses)\|[Constants](https://developer.android.com/reference/android/support/v4-media-session/MediaSessionCompat#constants)\|[Ctors](https://developer.android.com/reference/android/support/v4-media-session/MediaSessionCompat#pubctors)\|[Methods](https://developer.android.com/reference/android/support/v4-media-session/MediaSessionCompat#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v4-media-session/MediaSessionCompat#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v4-media-session/MediaSessionCompat#)  

# MediaSessionCompat

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public


class
MediaSessionCompat
`  
`

extends Object


``


`

|---|-----------------------------------------------------|
| java.lang.Object                                       ||
| ↳ | android.support.v4.media.session.MediaSessionCompat |

<br />

*** ** * ** ***

Allows interaction with media controllers, volume keys, media buttons, and transport controls.

A MediaSession should be created when an app wants to publish media playback information or handle media keys. In general an app only needs one session for all playback, though multiple sessions can be created to provide finer grain controls of media.

Once a session is created the owner of the session may pass its[session token](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getSessionToken())to other processes to allow them to create a[MediaControllerCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat)to interact with the session.

To receive commands, media keys, and other events a[MediaSessionCompat.Callback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback)must be set with[setCallback(Callback)](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setCallback(android.support.v4.media.session.MediaSessionCompat.Callback)).

When an app is finished performing playback it must call[release()](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#release())to clean up the session and notify any controllers.

MediaSessionCompat objects are not thread safe and all calls should be made from the same thread.

This is a helper for accessing features in[MediaSession](https://developer.android.com/reference/android/media/session/MediaSession.html)introduced after API level 4 in a backwards compatible fashion.  

### Developer Guides

For information about building your media application, read the[Media Apps](https://developer.android.com/guide/topics/media-apps)developer guide.

<br />

## Summary

|                                                                                                             ### Nested classes                                                                                                              ||
|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` class`     | [MediaSessionCompat.Callback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback) Receives transport controls, media buttons, and commands from controllers and the system. |
| ` interface` | [MediaSessionCompat.OnActiveChangeListener](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.OnActiveChangeListener) <br />                                                        |
| ` class`     | [MediaSessionCompat.QueueItem](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.QueueItem) A single item that is part of the play queue.                                           |
| ` class`     | [MediaSessionCompat.Token](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token) Represents an ongoing session.                                                                  |

|                                                                                                                                                                                                 ### Constants                                                                                                                                                                                                 ||
|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `String` | [ACTION_FLAG_AS_INAPPROPRIATE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ACTION_FLAG_AS_INAPPROPRIATE) Predefined custom action to flag the media that is currently playing as inappropriate.                                                                                                                                                     |
| `String` | [ACTION_FOLLOW](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ACTION_FOLLOW) Predefined custom action to follow an artist, album, or playlist.                                                                                                                                                                                                        |
| `String` | [ACTION_SKIP_AD](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ACTION_SKIP_AD) Predefined custom action to skip the advertisement that is currently playing.                                                                                                                                                                                          |
| `String` | [ACTION_UNFOLLOW](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ACTION_UNFOLLOW) Predefined custom action to unfollow an artist, album, or playlist.                                                                                                                                                                                                  |
| `String` | [ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE) Argument to indicate the media attribute.                                                                                                                                                                                                          |
| `String` | [ARGUMENT_MEDIA_ATTRIBUTE_VALUE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE_VALUE) String argument to indicate the value of the media attribute (e.g., the name of the artist).                                                                                                                                           |
| `int`    | [FLAG_HANDLES_MEDIA_BUTTONS](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#FLAG_HANDLES_MEDIA_BUTTONS) Sets this flag on the session to indicate that it can handle media button events.                                                                                                                                                              |
| `int`    | [FLAG_HANDLES_QUEUE_COMMANDS](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#FLAG_HANDLES_QUEUE_COMMANDS) Sets this flag on the session to indicate that it handles queue management commands through its[MediaSessionCompat.Callback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback).          |
| `int`    | [FLAG_HANDLES_TRANSPORT_CONTROLS](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#FLAG_HANDLES_TRANSPORT_CONTROLS) Sets this flag on the session to indicate that it handles transport control commands through its[MediaSessionCompat.Callback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback). |
| `int`    | [MEDIA_ATTRIBUTE_ALBUM](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MEDIA_ATTRIBUTE_ALBUM) The value of[ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)indicating the album.                                                                        |
| `int`    | [MEDIA_ATTRIBUTE_ARTIST](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MEDIA_ATTRIBUTE_ARTIST) The value of[ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)indicating the artist.                                                                     |
| `int`    | [MEDIA_ATTRIBUTE_PLAYLIST](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MEDIA_ATTRIBUTE_PLAYLIST) The value of[ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)indicating the playlist.                                                               |

|                                                                                                                                                                                                                                                                                                                               ### Public constructors                                                                                                                                                                                                                                                                                                                               ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[MediaSessionCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MediaSessionCompat(android.content.Context, java.lang.String))`(`[Context](https://developer.android.com/reference/android/content/Context.html)` context, String tag) ` Creates a new session.                                                                                                                                                                                                                                                                                                                                                              |
| ` `[MediaSessionCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MediaSessionCompat(android.content.Context, java.lang.String, android.content.ComponentName, android.app.PendingIntent))`(`[Context](https://developer.android.com/reference/android/content/Context.html)` context, String tag, `[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)` mbrComponent, `[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)` mbrIntent) ` Creates a new session with a specified media button receiver (a component name and/or a pending intent). |

|                                                                                                                                                                                                                                                                                                                ### Public methods                                                                                                                                                                                                                                                                                                                 ||
|----------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                                                                          | ` `[addOnActiveChangeListener](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#addOnActiveChangeListener(android.support.v4.media.session.MediaSessionCompat.OnActiveChangeListener))`(`[MediaSessionCompat.OnActiveChangeListener](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.OnActiveChangeListener)` listener) ` Adds a listener to be notified when the active status of this session changes.                 |
| ` static `[MediaSessionCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat)      | ` `[fromMediaSession](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#fromMediaSession(android.content.Context, java.lang.Object))`(`[Context](https://developer.android.com/reference/android/content/Context.html)` context, Object mediaSession) ` Creates an instance from a framework[MediaSession](https://developer.android.com/reference/android/media/session/MediaSession.html)object.                                                                    |
| ` `[MediaControllerCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat)       | ` `[getController](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getController())`() ` Gets a controller for this session.                                                                                                                                                                                                                                                                                                                                        |
| ` Object`                                                                                                                        | ` `[getMediaSession](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getMediaSession())`() ` Gets the underlying framework[MediaSession](https://developer.android.com/reference/android/media/session/MediaSession.html)object.                                                                                                                                                                                                                                    |
| ` Object`                                                                                                                        | ` `[getRemoteControlClient](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getRemoteControlClient())`() ` Gets the underlying framework[RemoteControlClient](https://developer.android.com/reference/android/media/RemoteControlClient.html)object.                                                                                                                                                                                                                |
| ` `[MediaSessionCompat.Token](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token) | ` `[getSessionToken](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getSessionToken())`() ` Retrieves a token object that can be used by apps to create a[MediaControllerCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat)for interacting with this session.                                                                                                                                                 |
| ` boolean`                                                                                                                       | ` `[isActive](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#isActive())`() ` Gets the current active state of this session.                                                                                                                                                                                                                                                                                                                                       |
| ` void`                                                                                                                          | ` `[release](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#release())`() ` This must be called when an app has finished performing playback.                                                                                                                                                                                                                                                                                                                      |
| ` void`                                                                                                                          | ` `[removeOnActiveChangeListener](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#removeOnActiveChangeListener(android.support.v4.media.session.MediaSessionCompat.OnActiveChangeListener))`(`[MediaSessionCompat.OnActiveChangeListener](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.OnActiveChangeListener)` listener) ` Stops the listener from being notified when the active status of this session changes.   |
| ` void`                                                                                                                          | ` `[sendSessionEvent](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#sendSessionEvent(java.lang.String, android.os.Bundle))`(String event, `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)` extras) ` Sends a proprietary event to all MediaControllers listening to this Session.                                                                                                                                                       |
| ` void`                                                                                                                          | ` `[setActive](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setActive(boolean))`(boolean active) ` Sets if this session is currently active and ready to receive commands.                                                                                                                                                                                                                                                                                       |
| ` void`                                                                                                                          | ` `[setCallback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setCallback(android.support.v4.media.session.MediaSessionCompat.Callback, android.os.Handler))`(`[MediaSessionCompat.Callback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback)` callback, `[Handler](https://developer.android.com/reference/android/os/Handler.html)` handler) ` Sets the callback to receive updates for the MediaSession. |
| ` void`                                                                                                                          | ` `[setCallback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setCallback(android.support.v4.media.session.MediaSessionCompat.Callback))`(`[MediaSessionCompat.Callback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback)` callback) ` Adds a callback to receive updates on for the MediaSession.                                                                                                          |
| ` void`                                                                                                                          | ` `[setCaptioningEnabled](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setCaptioningEnabled(boolean))`(boolean enabled) ` Enables/disables captioning for this session.                                                                                                                                                                                                                                                                                          |
| ` void`                                                                                                                          | ` `[setExtras](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setExtras(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle.html)` extras) ` Sets some extras that can be associated with the[MediaSessionCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat).                                                                                                               |
| ` void`                                                                                                                          | ` `[setFlags](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setFlags(int))`(int flags) ` Sets any flags for the session.                                                                                                                                                                                                                                                                                                                                          |
| ` void`                                                                                                                          | ` `[setMediaButtonReceiver](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setMediaButtonReceiver(android.app.PendingIntent))`(`[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)` mbr) ` Sets a pending intent for your media button receiver to allow restarting playback after the session has been stopped.                                                                                                              |
| ` void`                                                                                                                          | ` `[setMetadata](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setMetadata(android.support.v4.media.MediaMetadataCompat))`(`[MediaMetadataCompat](https://developer.android.com/reference/android/support/v4/media/MediaMetadataCompat)` metadata) ` Updates the current metadata.                                                                                                                                                                                |
| ` void`                                                                                                                          | ` `[setPlaybackState](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackState(android.support.v4.media.session.PlaybackStateCompat))`(`[PlaybackStateCompat](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat)` state) ` Updates the current playback state.                                                                                                                                                   |
| ` void`                                                                                                                          | ` `[setPlaybackToLocal](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackToLocal(int))`(int stream) ` Sets the stream this session is playing on.                                                                                                                                                                                                                                                                                                         |
| ` void`                                                                                                                          | ` `[setPlaybackToRemote](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackToRemote(android.support.v4.media.VolumeProviderCompat))`(`[VolumeProviderCompat](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat)` volumeProvider) ` Configures this session to use remote volume handling.                                                                                                                              |
| ` void`                                                                                                                          | ` `[setQueue](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setQueue(java.util.List<android.support.v4.media.session.MediaSessionCompat.QueueItem>))`(List<`[MediaSessionCompat.QueueItem](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.QueueItem)`> queue) ` Updates the list of items in the play queue.                                                                                                         |
| ` void`                                                                                                                          | ` `[setQueueTitle](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setQueueTitle(java.lang.CharSequence))`(CharSequence title) ` Sets the title of the play queue.                                                                                                                                                                                                                                                                                                  |
| ` void`                                                                                                                          | ` `[setRatingType](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setRatingType(int))`(int type) ` Sets the style of rating used by this session.                                                                                                                                                                                                                                                                                                                  |
| ` void`                                                                                                                          | ` `[setRepeatMode](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setRepeatMode(int))`(int repeatMode) ` Sets the repeat mode for this session.                                                                                                                                                                                                                                                                                                                    |
| ` void`                                                                                                                          | ` `[setSessionActivity](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setSessionActivity(android.app.PendingIntent))`(`[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)` pi) ` Sets an intent for launching UI for this Session.                                                                                                                                                                                           |
| ` void`                                                                                                                          | ` `[setShuffleMode](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setShuffleMode(int))`(int shuffleMode) ` Sets the shuffle mode for this session.                                                                                                                                                                                                                                                                                                                |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4-media-session/MediaSessionCompat#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Constants

### ACTION_FLAG_AS_INAPPROPRIATE

added in[version 25.4.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String ACTION_FLAG_AS_INAPPROPRIATE
```

Predefined custom action to flag the media that is currently playing as inappropriate.

<br />

**See also:**

- [onCustomAction(String, Bundle)](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback#onCustomAction(java.lang.String, android.os.Bundle))

Constant Value: "android.support.v4.media.session.action.FLAG_AS_INAPPROPRIATE"  

### ACTION_FOLLOW

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String ACTION_FOLLOW
```

Predefined custom action to follow an artist, album, or playlist. The extra bundle must have[ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)to indicate the type of the follow action. The bundle can also have an optional string argument,[ARGUMENT_MEDIA_ATTRIBUTE_VALUE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE_VALUE), to specify the target to follow (e.g., the name of the artist to follow). If this argument is omitted, the currently playing media will be the target of the action. Thus, the session must perform the follow action with the current metadata. If there's no specified attribute in the current metadata, the controller must not omit this argument.

<br />

**See also:**

- [ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)
- [ARGUMENT_MEDIA_ATTRIBUTE_VALUE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE_VALUE)
- [onCustomAction(String, Bundle)](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback#onCustomAction(java.lang.String, android.os.Bundle))

Constant Value: "android.support.v4.media.session.action.FOLLOW"  

### ACTION_SKIP_AD

added in[version 25.4.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String ACTION_SKIP_AD
```

Predefined custom action to skip the advertisement that is currently playing.

<br />

**See also:**

- [onCustomAction(String, Bundle)](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback#onCustomAction(java.lang.String, android.os.Bundle))

Constant Value: "android.support.v4.media.session.action.SKIP_AD"  

### ACTION_UNFOLLOW

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String ACTION_UNFOLLOW
```

Predefined custom action to unfollow an artist, album, or playlist. The extra bundle must have[ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)to indicate the type of the unfollow action. The bundle can also have an optional string argument,[ARGUMENT_MEDIA_ATTRIBUTE_VALUE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE_VALUE), to specify the target to unfollow (e.g., the name of the artist to unfollow). If this argument is omitted, the currently playing media will be the target of the action. Thus, the session must perform the unfollow action with the current metadata. If there's no specified attribute in the current metadata, the controller must not omit this argument.

<br />

**See also:**

- [ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)
- [ARGUMENT_MEDIA_ATTRIBUTE_VALUE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE_VALUE)
- [onCustomAction(String, Bundle)](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback#onCustomAction(java.lang.String, android.os.Bundle))

Constant Value: "android.support.v4.media.session.action.UNFOLLOW"  

### ARGUMENT_MEDIA_ATTRIBUTE

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String ARGUMENT_MEDIA_ATTRIBUTE
```

Argument to indicate the media attribute. It should be one of the following:

- [MEDIA_ATTRIBUTE_ARTIST](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MEDIA_ATTRIBUTE_ARTIST)
- [MEDIA_ATTRIBUTE_PLAYLIST](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MEDIA_ATTRIBUTE_PLAYLIST)
- [MEDIA_ATTRIBUTE_ALBUM](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MEDIA_ATTRIBUTE_ALBUM)

<br />

<br />

Constant Value: "android.support.v4.media.session.ARGUMENT_MEDIA_ATTRIBUTE"  

### ARGUMENT_MEDIA_ATTRIBUTE_VALUE

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String ARGUMENT_MEDIA_ATTRIBUTE_VALUE
```

String argument to indicate the value of the media attribute (e.g., the name of the artist).

<br />

Constant Value: "android.support.v4.media.session.ARGUMENT_MEDIA_ATTRIBUTE_VALUE"  

### FLAG_HANDLES_MEDIA_BUTTONS

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int FLAG_HANDLES_MEDIA_BUTTONS
```

Sets this flag on the session to indicate that it can handle media button events.

<br />

Constant Value: 1 (0x00000001)  

### FLAG_HANDLES_QUEUE_COMMANDS

added in[version 25.4.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int FLAG_HANDLES_QUEUE_COMMANDS
```

Sets this flag on the session to indicate that it handles queue management commands through its[MediaSessionCompat.Callback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback).

<br />

Constant Value: 4 (0x00000004)  

### FLAG_HANDLES_TRANSPORT_CONTROLS

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int FLAG_HANDLES_TRANSPORT_CONTROLS
```

Sets this flag on the session to indicate that it handles transport control commands through its[MediaSessionCompat.Callback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback).

<br />

Constant Value: 2 (0x00000002)  

### MEDIA_ATTRIBUTE_ALBUM

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int MEDIA_ATTRIBUTE_ALBUM
```

The value of[ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)indicating the album.

<br />

**See also:**

- [ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)

Constant Value: 1 (0x00000001)  

### MEDIA_ATTRIBUTE_ARTIST

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int MEDIA_ATTRIBUTE_ARTIST
```

The value of[ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)indicating the artist.

<br />

**See also:**

- [ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)

Constant Value: 0 (0x00000000)  

### MEDIA_ATTRIBUTE_PLAYLIST

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int MEDIA_ATTRIBUTE_PLAYLIST
```

The value of[ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)indicating the playlist.

<br />

**See also:**

- [ARGUMENT_MEDIA_ATTRIBUTE](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE)

Constant Value: 2 (0x00000002)

## Public constructors

### MediaSessionCompat

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
MediaSessionCompat (Context context,
                String tag)
```

Creates a new session. You must call[release()](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#release())when finished with the session.

The session will automatically be registered with the system but will not be published until[setActive(true)](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setActive(boolean))is called.

For API 20 or earlier, note that a media button receiver is required for handling[ACTION_MEDIA_BUTTON](https://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_BUTTON). This constructor will attempt to find an appropriate[BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver.html)from your manifest. See[MediaButtonReceiver](https://developer.android.com/reference/android/support/v4/media/session/MediaButtonReceiver)for more details.

<br />

<br />

|                               Parameters                               ||
|-----------|-------------------------------------------------------------|
| `context` | `Context`: The context to use to create the session. <br /> |
| `tag`     | `String`: A short name for debugging purposes. <br />       |

### MediaSessionCompat

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
MediaSessionCompat (Context context,
                String tag,
                ComponentName mbrComponent,
                PendingIntent mbrIntent)
```

Creates a new session with a specified media button receiver (a component name and/or a pending intent). You must call[release()](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#release())when finished with the session.

The session will automatically be registered with the system but will not be published until[setActive(true)](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setActive(boolean))is called.

For API 20 or earlier, note that a media button receiver is required for handling[ACTION_MEDIA_BUTTON](https://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_BUTTON). This constructor will attempt to find an appropriate[BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver.html)from your manifest if it's not specified. See[MediaButtonReceiver](https://developer.android.com/reference/android/support/v4/media/session/MediaButtonReceiver)for more details.

<br />

<br />

|                                                                                                                                                                                                        Parameters                                                                                                                                                                                                         ||
|----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context`      | `Context`: The context to use to create the session. <br />                                                                                                                                                                                                                                                                                                                                               |
| `tag`          | `String`: A short name for debugging purposes. <br />                                                                                                                                                                                                                                                                                                                                                     |
| `mbrComponent` | `ComponentName`: The component name for your media button receiver. <br />                                                                                                                                                                                                                                                                                                                                |
| `mbrIntent`    | `PendingIntent`: The PendingIntent for your receiver component that handles media button events. This is optional and will be used on between[JELLY_BEAN_MR2](https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#JELLY_BEAN_MR2)and[KITKAT_WATCH](https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#KITKAT_WATCH)instead of the component name. <br /> |

## Public methods

### addOnActiveChangeListener

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void addOnActiveChangeListener (MediaSessionCompat.OnActiveChangeListener listener)
```

Adds a listener to be notified when the active status of this session changes. This is primarily used by the support library and should not be needed by apps.

<br />

|                                      Parameters                                      ||
|------------|--------------------------------------------------------------------------|
| `listener` | `MediaSessionCompat.OnActiveChangeListener`: The listener to add. <br /> |

### fromMediaSession

added in[version 25.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
MediaSessionCompat fromMediaSession (Context context,
                Object mediaSession)
```

Creates an instance from a framework[MediaSession](https://developer.android.com/reference/android/media/session/MediaSession.html)object.

This method is only supported on API 21+. On API 20 and below, it returns null.

<br />

<br />

|                                                                Parameters                                                                ||
|----------------|--------------------------------------------------------------------------------------------------------------------------|
| `context`      | `Context`: The context to use to create the session. <br />                                                              |
| `mediaSession` | `Object`: A[MediaSession](https://developer.android.com/reference/android/media/session/MediaSession.html)object. <br /> |

|                                                                                                                                     Returns                                                                                                                                      ||
|-------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [MediaSessionCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat) | An equivalent[MediaSessionCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat)object, or null if none. <br /> |

### getController

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
MediaControllerCompat getController ()
```

Gets a controller for this session. This is a convenience method to avoid having to cache your own controller in process.

<br />

|                                                                            Returns                                                                             ||
|-------------------------------------------------------------------------------------------------------------------------|---------------------------------------|
| [MediaControllerCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat) | A controller for this session. <br /> |

### getMediaSession

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Object getMediaSession ()
```

Gets the underlying framework[MediaSession](https://developer.android.com/reference/android/media/session/MediaSession.html)object.

This method is only supported on API 21+.

<br />

<br />

|                                                                        Returns                                                                         ||
|----------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `Object` | The underlying[MediaSession](https://developer.android.com/reference/android/media/session/MediaSession.html)object, or null if none. <br /> |

### getRemoteControlClient

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Object getRemoteControlClient ()
```

Gets the underlying framework[RemoteControlClient](https://developer.android.com/reference/android/media/RemoteControlClient.html)object.

This method is only supported on APIs 14-20. On API 21+[getMediaSession()](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getMediaSession())should be used instead.

<br />

|                                                                           Returns                                                                            ||
|----------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| `Object` | The underlying[RemoteControlClient](https://developer.android.com/reference/android/media/RemoteControlClient.html)object, or null if none. <br /> |

### getSessionToken

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
MediaSessionCompat.Token getSessionToken ()
```

Retrieves a token object that can be used by apps to create a[MediaControllerCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat)for interacting with this session. The owner of the session is responsible for deciding how to distribute these tokens.

On platform versions before[LOLLIPOP](https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#LOLLIPOP)this token may only be used within your app as there is no way to guarantee other apps are using the same version of the support library.

<br />

|                                                                                                    Returns                                                                                                    ||
|-------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| [MediaSessionCompat.Token](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token) | A token that can be used to create a media controller for this session. <br /> |

### isActive

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isActive ()
```

Gets the current active state of this session.

<br />

|                              Returns                              ||
|-----------|--------------------------------------------------------|
| `boolean` | True if the session is active, false otherwise. <br /> |

### release

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void release ()
```

This must be called when an app has finished performing playback. If playback is expected to start again shortly the session can be left open, but it must be released if your activity or service is being destroyed.

<br />

### removeOnActiveChangeListener

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void removeOnActiveChangeListener (MediaSessionCompat.OnActiveChangeListener listener)
```

Stops the listener from being notified when the active status of this session changes.

<br />

|                                       Parameters                                        ||
|------------|-----------------------------------------------------------------------------|
| `listener` | `MediaSessionCompat.OnActiveChangeListener`: The listener to remove. <br /> |

### sendSessionEvent

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void sendSessionEvent (String event,
                Bundle extras)
```

Sends a proprietary event to all MediaControllers listening to this Session. It's up to the Controller/Session owner to determine the meaning of any events.

<br />

|                          Parameters                           ||
|----------|-----------------------------------------------------|
| `event`  | `String`: The name of the event to send <br />      |
| `extras` | `Bundle`: Any extras included with the event <br /> |

### setActive

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setActive (boolean active)
```

Sets if this session is currently active and ready to receive commands. If set to false your session's controller may not be discoverable. You must set the session to active before it can start receiving media button events or transport commands.

On platforms earlier than[LOLLIPOP](https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#LOLLIPOP), a media button event receiver should be set via the constructor to receive media button events.

<br />

|                             Parameters                             ||
|----------|----------------------------------------------------------|
| `active` | `boolean`: Whether this session is active or not. <br /> |

### setCallback

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setCallback (MediaSessionCompat.Callback callback,
                Handler handler)
```

Sets the callback to receive updates for the MediaSession. This includes media button and volume events. Set the callback to null to stop receiving events.

<br />

|                                      Parameters                                       ||
|------------|---------------------------------------------------------------------------|
| `callback` | `MediaSessionCompat.Callback`: The callback to receive updates on. <br /> |
| `handler`  | `Handler`: The handler that events should be posted on. <br />            |

### setCallback

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setCallback (MediaSessionCompat.Callback callback)
```

Adds a callback to receive updates on for the MediaSession. This includes media button and volume events. The caller's thread will be used to post events.

<br />

|                              Parameters                               ||
|------------|-----------------------------------------------------------|
| `callback` | `MediaSessionCompat.Callback`: The callback object <br /> |

### setCaptioningEnabled

added in[version 25.4.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setCaptioningEnabled (boolean enabled)
```

Enables/disables captioning for this session.

<br />

|                                Parameters                                 ||
|-----------|----------------------------------------------------------------|
| `enabled` | `boolean`:`true`to enable captioning,`false`to disable. <br /> |

### setExtras

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setExtras (Bundle extras)
```

Sets some extras that can be associated with the[MediaSessionCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat). No assumptions should be made as to how a[MediaControllerCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat)will handle these extras. Keys should be fully qualified (e.g. com.example.MY_EXTRA) to avoid conflicts.

<br />

|                             Parameters                             ||
|----------|----------------------------------------------------------|
| `extras` | `Bundle`: The extras associated with the session. <br /> |

### setFlags

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setFlags (int flags)
```

Sets any flags for the session.

<br />

|                        Parameters                         ||
|---------|--------------------------------------------------|
| `flags` | `int`: The flags to set for this session. <br /> |

### setMediaButtonReceiver

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setMediaButtonReceiver (PendingIntent mbr)
```

Sets a pending intent for your media button receiver to allow restarting playback after the session has been stopped. If your app is started in this way an[ACTION_MEDIA_BUTTON](https://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_BUTTON)intent will be sent via the pending intent.

This method will only work on[LOLLIPOP](https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#LOLLIPOP)and later. Earlier platform versions must include the media button receiver in the constructor.

<br />

|                                                                         Parameters                                                                          ||
|-------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mbr` | `PendingIntent`: The[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)to send the media button event to. <br /> |

### setMetadata

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setMetadata (MediaMetadataCompat metadata)
```

Updates the current metadata. New metadata can be created using[MediaMetadataCompat.Builder](https://developer.android.com/reference/android/support/v4/media/MediaMetadataCompat.Builder). This operation may take time proportional to the size of the bitmap to replace large bitmaps with a scaled down copy.

<br />

|                         Parameters                         ||
|------------|------------------------------------------------|
| `metadata` | `MediaMetadataCompat`: The new metadata <br /> |

**See also:**

- [putBitmap(String, Bitmap)](https://developer.android.com/reference/android/support/v4/media/MediaMetadataCompat.Builder#putBitmap(java.lang.String, android.graphics.Bitmap))  

### setPlaybackState

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setPlaybackState (PlaybackStateCompat state)
```

Updates the current playback state.

<br />

|                              Parameters                              ||
|---------|-------------------------------------------------------------|
| `state` | `PlaybackStateCompat`: The current state of playback <br /> |

### setPlaybackToLocal

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setPlaybackToLocal (int stream)
```

Sets the stream this session is playing on. This will affect the system's volume handling for this session. If[setPlaybackToRemote(VolumeProviderCompat)](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackToRemote(android.support.v4.media.VolumeProviderCompat))was previously called it will stop receiving volume commands and the system will begin sending volume changes to the appropriate stream.

By default sessions are on[STREAM_MUSIC](https://developer.android.com/reference/android/media/AudioManager.html#STREAM_MUSIC).

<br />

|                                                                      Parameters                                                                      ||
|----------|--------------------------------------------------------------------------------------------------------------------------------------------|
| `stream` | `int`: The[AudioManager](https://developer.android.com/reference/android/media/AudioManager.html)stream this session is playing on. <br /> |

### setPlaybackToRemote

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setPlaybackToRemote (VolumeProviderCompat volumeProvider)
```

Configures this session to use remote volume handling. This must be called to receive volume button events, otherwise the system will adjust the current stream volume for this session. If[setPlaybackToLocal(int)](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackToLocal(int))was previously called that stream will stop receiving volume changes for this session.

On platforms earlier than[LOLLIPOP](https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#LOLLIPOP)this will only allow an app to handle volume commands sent directly to the session by a[MediaControllerCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat). System routing of volume keys will not use the volume provider.

<br />

|                                                   Parameters                                                    ||
|------------------|-----------------------------------------------------------------------------------------------|
| `volumeProvider` | `VolumeProviderCompat`: The provider that will handle volume changes. May not be null. <br /> |

### setQueue

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setQueue (List<MediaSessionCompat.QueueItem> queue)
```

Updates the list of items in the play queue. It is an ordered list and should contain the current item, and previous or upcoming items if they exist. Specify null if there is no current play queue.

The queue should be of reasonable size. If the play queue is unbounded within your app, it is better to send a reasonable amount in a sliding window instead.

<br />

|                         Parameters                         ||
|---------|---------------------------------------------------|
| `queue` | `List`: A list of items in the play queue. <br /> |

### setQueueTitle

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setQueueTitle (CharSequence title)
```

Sets the title of the play queue. The UI should display this title along with the play queue itself. e.g. "Play Queue", "Now Playing", or an album name.

<br />

|                          Parameters                          ||
|---------|-----------------------------------------------------|
| `title` | `CharSequence`: The title of the play queue. <br /> |

### setRatingType

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setRatingType (int type)
```

Sets the style of rating used by this session. Apps trying to set the rating should use this style. Must be one of the following:

- [RATING_NONE](https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_NONE)
- [RATING_3_STARS](https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_3_STARS)
- [RATING_4_STARS](https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_4_STARS)
- [RATING_5_STARS](https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_5_STARS)
- [RATING_HEART](https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_HEART)
- [RATING_PERCENTAGE](https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_PERCENTAGE)
- [RATING_THUMB_UP_DOWN](https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_THUMB_UP_DOWN)

<br />

<br />

|      Parameters      ||
|--------|--------------|
| `type` | `int` <br /> |

### setRepeatMode

added in[version 25.4.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setRepeatMode (int repeatMode)
```

Sets the repeat mode for this session.

Note that if this method is not called before,[getRepeatMode()](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat#getRepeatMode())will return[REPEAT_MODE_NONE](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat#REPEAT_MODE_NONE).

<br />

|                                                                                                                                                                                                                                                                                                    Parameters                                                                                                                                                                                                                                                                                                    ||
|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `repeatMode` | `int`: The repeat mode. Must be one of the followings:[REPEAT_MODE_NONE](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat#REPEAT_MODE_NONE),[REPEAT_MODE_ONE](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat#REPEAT_MODE_ONE),[REPEAT_MODE_ALL](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat#REPEAT_MODE_ALL),[REPEAT_MODE_GROUP](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat#REPEAT_MODE_GROUP) <br /> |

### setSessionActivity

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setSessionActivity (PendingIntent pi)
```

Sets an intent for launching UI for this Session. This can be used as a quick link to an ongoing media screen. The intent should be for an activity that may be started using[startActivity(Intent)](https://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent)).

<br />

|                                   Parameters                                    ||
|------|---------------------------------------------------------------------------|
| `pi` | `PendingIntent`: The intent to launch to show UI for this Session. <br /> |

### setShuffleMode

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setShuffleMode (int shuffleMode)
```

Sets the shuffle mode for this session.

Note that if this method is not called before,[getShuffleMode()](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat#getShuffleMode())will return[SHUFFLE_MODE_NONE](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat#SHUFFLE_MODE_NONE).

<br />

|                                                                                                                                                                                                                                        Parameters                                                                                                                                                                                                                                        ||
|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `shuffleMode` | `int`: The shuffle mode. Must be one of the followings:[SHUFFLE_MODE_NONE](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat#SHUFFLE_MODE_NONE),[SHUFFLE_MODE_ALL](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat#SHUFFLE_MODE_ALL),[SHUFFLE_MODE_GROUP](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat#SHUFFLE_MODE_GROUP) <br /> |

-

  ## Interfaces

  - [MediaSessionCompat.OnActiveChangeListener](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.OnActiveChangeListener)
-

  ## Classes

  - [MediaButtonReceiver](https://developer.android.com/reference/android/support/v4/media/session/MediaButtonReceiver)
  - [MediaControllerCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat)
  - [MediaControllerCompat.Callback](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat.Callback)
  - [MediaControllerCompat.PlaybackInfo](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat.PlaybackInfo)
  - [MediaControllerCompat.TransportControls](https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat.TransportControls)
  - [MediaSessionCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat)
  - [MediaSessionCompat.Callback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback)
  - [MediaSessionCompat.QueueItem](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.QueueItem)
  - [MediaSessionCompat.Token](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token)
  - [ParcelableVolumeInfo](https://developer.android.com/reference/android/support/v4/media/session/ParcelableVolumeInfo)
  - [PlaybackStateCompat](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat)
  - [PlaybackStateCompat.Builder](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat.Builder)
  - [PlaybackStateCompat.CustomAction](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat.CustomAction)
  - [PlaybackStateCompat.CustomAction.Builder](https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat.CustomAction.Builder)