# MediaSessionCompat

Artifact: [androidx.media:media](https://developer.android.com/jetpack/androidx/releases/media) [View Source](https://cs.android.com/search?q=file:android/support/v4/media/session/MediaSessionCompat.java+class:android.support.v4.media.session.MediaSessionCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

*** ** * ** ***


```
public class MediaSessionCompat
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> androidx.media is deprecated. Please migrate to [androidx.media3](https://developer.android.com/media/media3).

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 `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getSessionToken()` to other processes to allow them to create a `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 `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback` must be set with `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 `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 `https://developer.android.com/reference/android/media/session/MediaSession.html` introduced after API level 4 in a backwards compatible fashion.

## Summary

| ### Nested types |
|---|
| `public abstract class https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback` **This class is deprecated.** androidx.media is deprecated. <br /> |
| `public interface https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.OnActiveChangeListener` **This interface is deprecated.** androidx.media is deprecated. <br /> |
| `public final class https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.QueueItem implements https://developer.android.com/reference/android/os/Parcelable.html` **This class is deprecated.** androidx.media is deprecated. <br /> |
| `public final class https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token implements https://developer.android.com/reference/android/os/Parcelable.html` **This class is deprecated.** androidx.media is deprecated. <br /> |

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ACTION_FLAG_AS_INAPPROPRIATE() = "android.support.v4.media.session.action.FLAG_AS_INAPPROPRIATE"` **This field is deprecated.** Deprecated in Java |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ACTION_FOLLOW() = "android.support.v4.media.session.action.FOLLOW"` **This field is deprecated.** Deprecated in Java |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ACTION_SKIP_AD() = "android.support.v4.media.session.action.SKIP_AD"` **This field is deprecated.** Deprecated in Java |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ACTION_UNFOLLOW() = "android.support.v4.media.session.action.UNFOLLOW"` **This field is deprecated.** Deprecated in Java |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE() = "android.support.v4.media.session.ARGUMENT_MEDIA_ATTRIBUTE"` **This field is deprecated.** Deprecated in Java |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE_VALUE() = "android.support.v4.media.session.ARGUMENT_MEDIA_ATTRIBUTE_VALUE"` **This field is deprecated.** Deprecated in Java |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#FLAG_HANDLES_MEDIA_BUTTONS() = 1` **This field is deprecated.** This flag is no longer used. <br /> |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#FLAG_HANDLES_QUEUE_COMMANDS() = 4` **This field is deprecated.** Deprecated in Java |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#FLAG_HANDLES_TRANSPORT_CONTROLS() = 2` **This field is deprecated.** This flag is no longer used. <br /> |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MEDIA_ATTRIBUTE_ALBUM() = 1` **This field is deprecated.** Deprecated in Java |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MEDIA_ATTRIBUTE_ARTIST() = 0` **This field is deprecated.** Deprecated in Java |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MEDIA_ATTRIBUTE_PLAYLIST() = 2` **This field is deprecated.** Deprecated in Java |

| ### Public constructors |
|---|
| `[MediaSessionCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MediaSessionCompat(android.content.Context,java.lang.String))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html tag)` **This method is deprecated.** Deprecated in Java |
| `[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))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html tag, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/ComponentName.html mbrComponent, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/app/PendingIntent.html mbrIntent )` **This method is deprecated.** Deprecated in Java |
| `[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,android.os.Bundle))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html tag, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/ComponentName.html mbrComponent, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/app/PendingIntent.html mbrIntent, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html sessionInfo )` **This method is deprecated.** Deprecated in Java |

| ### Public methods |
|---|---|
| `void` | `[addOnActiveChangeListener](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#addOnActiveChangeListener(android.support.v4.media.session.MediaSessionCompat.OnActiveChangeListener))( https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.OnActiveChangeListener listener )` **This method is deprecated.** Deprecated in Java |
| `static 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))(https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/Object.html mediaSession)` **This method is deprecated.** Deprecated in Java |
| `static int` | `[getBitmapDimensionLimit](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getBitmapDimensionLimit())()` **This method is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat` | `[getController](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getController())()` **This method is deprecated.** Deprecated in Java |
| `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/media/MediaSessionManager.RemoteUserInfo` | `[getCurrentControllerInfo](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getCurrentControllerInfo())()` **This method is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/java/lang/Object.html` | `[getMediaSession](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getMediaSession())()` **This method is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/java/lang/Object.html` | `[getRemoteControlClient](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getRemoteControlClient())()` **This method is deprecated.** Deprecated in Java |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `[getScaledBitmap](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getScaledBitmap(android.graphics.Bitmap))(https://developer.android.com/reference/android/graphics/Bitmap.html bitmap)` **This method is deprecated.** Deprecated in Java |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `[getScaledBitmap](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getScaledBitmap(android.graphics.Bitmap,int))(https://developer.android.com/reference/android/graphics/Bitmap.html bitmap, int dimensionLimit)` **This method is deprecated.** Deprecated in Java |
| `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())()` **This method is deprecated.** Deprecated in Java |
| `boolean` | `[isActive](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#isActive())()` **This method is deprecated.** Deprecated in Java |
| `void` | `[release](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#release())()` **This method is deprecated.** Deprecated in Java |
| `void` | `[removeOnActiveChangeListener](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#removeOnActiveChangeListener(android.support.v4.media.session.MediaSessionCompat.OnActiveChangeListener))( https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.OnActiveChangeListener listener )` **This method is deprecated.** Deprecated in Java |
| `void` | `[sendSessionEvent](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#sendSessionEvent(java.lang.String,android.os.Bundle))(https://developer.android.com/reference/java/lang/String.html event, https://developer.android.com/reference/android/os/Bundle.html extras)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setActive](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setActive(boolean))(boolean active)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setCallback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setCallback(android.support.v4.media.session.MediaSessionCompat.Callback))(https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback callback)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setCallback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setCallback(android.support.v4.media.session.MediaSessionCompat.Callback,android.os.Handler))(https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback callback, https://developer.android.com/reference/android/os/Handler.html handler)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setCaptioningEnabled](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setCaptioningEnabled(boolean))(boolean enabled)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setExtras](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setExtras(android.os.Bundle))(https://developer.android.com/reference/android/os/Bundle.html extras)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setFlags](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setFlags(int))(int flags)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setMediaButtonReceiver](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setMediaButtonReceiver(android.app.PendingIntent))(https://developer.android.com/reference/android/app/PendingIntent.html mbr)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setMetadata](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setMetadata(android.support.v4.media.MediaMetadataCompat))(https://developer.android.com/reference/android/support/v4/media/MediaMetadataCompat metadata)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setPlaybackState](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackState(android.support.v4.media.session.PlaybackStateCompat))(https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat state)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setPlaybackToLocal](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackToLocal(int))(int stream)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setPlaybackToRemote](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackToRemote(androidx.media.VolumeProviderCompat))(https://developer.android.com/reference/androidx/media/VolumeProviderCompat volumeProvider)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setQueue](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setQueue(java.util.List<android.support.v4.media.session.MediaSessionCompat.QueueItem>))(https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.QueueItem> queue)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setQueueTitle](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setQueueTitle(java.lang.CharSequence))(https://developer.android.com/reference/java/lang/CharSequence.html title)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setRatingType](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setRatingType(int))(int type)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setRepeatMode](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setRepeatMode(int))(int repeatMode)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setSessionActivity](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setSessionActivity(android.app.PendingIntent))(https://developer.android.com/reference/android/app/PendingIntent.html pi)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setShuffleMode](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setShuffleMode(int))(int shuffleMode)` **This method is deprecated.** Deprecated in Java |

## Constants

### ACTION_FLAG_AS_INAPPROPRIATE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final String ACTION_FLAG_AS_INAPPROPRIATE = "android.support.v4.media.session.action.FLAG_AS_INAPPROPRIATE"
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

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

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

### ACTION_FOLLOW

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final String ACTION_FOLLOW = "android.support.v4.media.session.action.FOLLOW"
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

Predefined custom action to follow an artist, album, or playlist. The extra bundle must have `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, `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.

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

### ACTION_SKIP_AD

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final String ACTION_SKIP_AD = "android.support.v4.media.session.action.SKIP_AD"
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

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

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

### ACTION_UNFOLLOW

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final String ACTION_UNFOLLOW = "android.support.v4.media.session.action.UNFOLLOW"
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

Predefined custom action to unfollow an artist, album, or playlist. The extra bundle must have `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, `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.

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

### ARGUMENT_MEDIA_ATTRIBUTE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final String ARGUMENT_MEDIA_ATTRIBUTE = "android.support.v4.media.session.ARGUMENT_MEDIA_ATTRIBUTE"
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

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

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

### ARGUMENT_MEDIA_ATTRIBUTE_VALUE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final String ARGUMENT_MEDIA_ATTRIBUTE_VALUE = "android.support.v4.media.session.ARGUMENT_MEDIA_ATTRIBUTE_VALUE"
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

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

### FLAG_HANDLES_MEDIA_BUTTONS

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0)

```
public static final int FLAG_HANDLES_MEDIA_BUTTONS = 1
```

> [!CAUTION]
> **This field is deprecated.**   
>
> This flag is no longer used. All media sessions are expected to handle media button events now. For backward compatibility, this flag will be always set.

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

### FLAG_HANDLES_QUEUE_COMMANDS

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final int FLAG_HANDLES_QUEUE_COMMANDS = 4
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

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

### FLAG_HANDLES_TRANSPORT_CONTROLS

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0)

```
public static final int FLAG_HANDLES_TRANSPORT_CONTROLS = 2
```

> [!CAUTION]
> **This field is deprecated.**   
>
> This flag is no longer used. All media sessions are expected to handle transport controls now. For backward compatibility, this flag will be always set.

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

### MEDIA_ATTRIBUTE_ALBUM

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final int MEDIA_ATTRIBUTE_ALBUM = 1
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

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

| See also |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE()` |   |

### MEDIA_ATTRIBUTE_ARTIST

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final int MEDIA_ATTRIBUTE_ARTIST = 0
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

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

| See also |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE()` |   |

### MEDIA_ATTRIBUTE_PLAYLIST

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final int MEDIA_ATTRIBUTE_PLAYLIST = 2
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

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

| See also |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#ARGUMENT_MEDIA_ATTRIBUTE()` |   |

## Public constructors

### MediaSessionCompat

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public [MediaSessionCompat](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MediaSessionCompat(android.content.Context,java.lang.String))(@NonNull Context context, @NonNull String tag)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Creates a new session. You must call `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 `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 `https://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_BUTTON`. This constructor will attempt to find an appropriate `https://developer.android.com/reference/android/content/BroadcastReceiver.html` from your manifest. See `https://developer.android.com/reference/androidx/media/session/MediaButtonReceiver` for more details.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The context to use to create the session. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html tag` | A short name for debugging purposes. |

### MediaSessionCompat

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public [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))(
    @NonNull Context context,
    @NonNull String tag,
    @Nullable ComponentName mbrComponent,
    @Nullable PendingIntent mbrIntent
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Creates a new session with a specified media button receiver (a component name and/or a pending intent). You must call `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 `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 `https://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_BUTTON`. This constructor will attempt to find an appropriate `https://developer.android.com/reference/android/content/BroadcastReceiver.html` from your manifest if it's not specified. See `https://developer.android.com/reference/androidx/media/session/MediaButtonReceiver` for more details.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The context to use to create the session. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html tag` | A short name for debugging purposes. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/ComponentName.html mbrComponent` | The component name for your media button receiver. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/app/PendingIntent.html mbrIntent` | The PendingIntent for your receiver component that handles media button events. This is optional and will be used on between `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#JELLY_BEAN_MR2` and `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#KITKAT_WATCH` instead of the component name. |

### MediaSessionCompat

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/media#1.2.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public [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,android.os.Bundle))(
    @NonNull Context context,
    @NonNull String tag,
    @Nullable ComponentName mbrComponent,
    @Nullable PendingIntent mbrIntent,
    @Nullable Bundle sessionInfo
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Creates a new session with a specified media button receiver (a component name and/or a pending intent). You must call `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 `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 `https://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_BUTTON`. This constructor will attempt to find an appropriate `https://developer.android.com/reference/android/content/BroadcastReceiver.html` from your manifest if it's not specified. See `https://developer.android.com/reference/androidx/media/session/MediaButtonReceiver` for more details.
The `sessionInfo` can include additional unchanging information about this session. For example, it can include the version of the application, or other app-specific unchanging information.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The context to use to create the session. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html tag` | A short name for debugging purposes. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/ComponentName.html mbrComponent` | The component name for your media button receiver. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/app/PendingIntent.html mbrIntent` | The PendingIntent for your receiver component that handles media button events. This is optional and will be used on between `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#JELLY_BEAN_MR2` and `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#KITKAT_WATCH` instead of the component name. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html sessionInfo` | A bundle for additional information about this session, or `https://developer.android.com/reference/android/os/Bundle.html#EMPTY` if none. Controllers can get this information by calling `https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat#getSessionInfo()`. An `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` will be thrown if this contains any non-framework Parcelable objects. |

## Public methods

### addOnActiveChangeListener

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [addOnActiveChangeListener](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#addOnActiveChangeListener(android.support.v4.media.session.MediaSessionCompat.OnActiveChangeListener))(
    MediaSessionCompat.OnActiveChangeListener listener
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.OnActiveChangeListener listener` | The listener to add. |

### fromMediaSession

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static MediaSessionCompat [fromMediaSession](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#fromMediaSession(android.content.Context,java.lang.Object))(Context context, Object mediaSession)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Creates an instance from a framework `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.

Note: A `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat` object returned from this method may not provide the full functionality of `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat` until setting a new `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback`. To avoid this, when both a `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat` and a framework `https://developer.android.com/reference/android/media/session/MediaSession.html` are needed, it is recommended to create a `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat` first and get the framework session through `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getMediaSession()`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | The context to use to create the session. |
| `https://developer.android.com/reference/java/lang/Object.html mediaSession` | A `https://developer.android.com/reference/android/media/session/MediaSession.html` object. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat` | An equivalent `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat` object, or null if none. |

### getBitmapDimensionLimit

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static int [getBitmapDimensionLimit](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getBitmapDimensionLimit())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Gets the bitmap dimension limit in pixels. Bitmaps with width or height larger than this will be scaled down to fit within the limit. Apps are recommended to use bitmaps whose width or height is no larger than this limit. Otherwise, for example, when setting a bitmap in MediaSession metadata MediaSession.setMetadata, a downscaling will be performed, which incurs performance cost as well as an intermediate scaled down bitmap. Example usage:

```
  int width = calculateRequestBitmapWidthPx();
  int height = calculateRequestBitmapHeightPx();
  final int limit = mediaSession.getBitmapDimensionLimit();
  if (width >= limit || height >= limit) {
    float scale = Math.max((float)(width) / limit,
                           (float)(height) / limit);
    if (scale < THRESHOLD) {
      width = (int)(width * scale);
      height = (int)(height * scale);
    }
  }

  Bitmap bitmap = BitmapLoader.load(uri, width, height);
```

### getController

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public MediaControllerCompat [getController](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getController())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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

| Returns |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat` | A controller for this session. |

### getCurrentControllerInfo

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public final @NonNull MediaSessionManager.RemoteUserInfo [getCurrentControllerInfo](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getCurrentControllerInfo())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Gets the controller information who sent the current request.

Note: This is only valid while in a request callback, such as `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback#onPlay()`.

Note: From API 21 to 23, this method returns a fake `https://developer.android.com/reference/androidx/media/MediaSessionManager.RemoteUserInfo` which has following values:

- Package name is `https://developer.android.com/reference/androidx/media/MediaSessionManager.RemoteUserInfo#LEGACY_CONTROLLER()`.
- PID and UID will have negative values.

Note: From API 24 to 27, the `https://developer.android.com/reference/androidx/media/MediaSessionManager.RemoteUserInfo` returned from this method will have negative uid and pid. Most of the cases it will have the correct package name, but sometimes it will fail to get the right one.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/media/MediaSessionManager.RemoteUserInfo#LEGACY_CONTROLLER()` |   |
| `https://developer.android.com/reference/androidx/media/MediaSessionManager#isTrustedForMediaControl(androidx.media.MediaSessionManager.RemoteUserInfo)` |   |

### getMediaSession

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public Object [getMediaSession](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getMediaSession())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Gets the underlying framework `https://developer.android.com/reference/android/media/session/MediaSession.html` object.

This method is only supported on API 21+.

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/Object.html` | The underlying `https://developer.android.com/reference/android/media/session/MediaSession.html` object, or null if none. |

### getRemoteControlClient

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public Object [getRemoteControlClient](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getRemoteControlClient())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Gets the underlying framework `https://developer.android.com/reference/android/media/RemoteControlClient.html` object.

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

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/Object.html` | The underlying `https://developer.android.com/reference/android/media/RemoteControlClient.html` object, or null if none. |

### getScaledBitmap

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static Bitmap [getScaledBitmap](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getScaledBitmap(android.graphics.Bitmap))(Bitmap bitmap)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Scales down the given bitmap if its width or height exceeds the limit returned by `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getBitmapDimensionLimit()`. The bitmap will be scaled to fit within the limit while maintaining its aspect ratio. On API 31+, the returned bitmap will be a shared bitmap.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html bitmap` | The bitmap to potentially scale. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html` | The original bitmap if it's within the dimension limit, or a scaled-down version. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getBitmapDimensionLimit()` |   |

### getScaledBitmap

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static Bitmap [getScaledBitmap](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getScaledBitmap(android.graphics.Bitmap,int))(Bitmap bitmap, int dimensionLimit)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Scales down the given bitmap if its width or height exceeds either the provided `dimensionLimit` or the limit returned by `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getBitmapDimensionLimit()`. The bitmap will be scaled to fit within that limit while maintaining its aspect ratio. On API 31+, the returned bitmap will be a shared bitmap.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html bitmap` | The bitmap to potentially scale. |
| `int dimensionLimit` | The maximum allowed width or height for the bitmap. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html` | The original bitmap if it's within the dimension limit, or a scaled-down version. |

### getSessionToken

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public MediaSessionCompat.Token [getSessionToken](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#getSessionToken())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Retrieves a token object that can be used by apps to create a `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 `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.

| Returns |
|---|---|
| `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. |

### isActive

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public boolean [isActive](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#isActive())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Gets the current active state of this session.

| Returns |
|---|---|
| `boolean` | True if the session is active, false otherwise. |

### release

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [release](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#release())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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.

### removeOnActiveChangeListener

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [removeOnActiveChangeListener](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#removeOnActiveChangeListener(android.support.v4.media.session.MediaSessionCompat.OnActiveChangeListener))(
    MediaSessionCompat.OnActiveChangeListener listener
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.OnActiveChangeListener listener` | The listener to remove. |

### sendSessionEvent

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [sendSessionEvent](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#sendSessionEvent(java.lang.String,android.os.Bundle))(String event, Bundle extras)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html event` | The name of the event to send |
| `https://developer.android.com/reference/android/os/Bundle.html extras` | Any extras included with the event |

### setActive

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setActive](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setActive(boolean))(boolean active)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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 `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.

| Parameters |
|---|---|
| `boolean active` | Whether this session is active or not. |

### setCallback

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setCallback](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setCallback(android.support.v4.media.session.MediaSessionCompat.Callback))(MediaSessionCompat.Callback callback)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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. Set the callback to null to stop receiving events.

Don't reuse the callback among the sessions. Callbacks keep internal reference to the session when it's set, so it may misbehave.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback callback` | The callback object |

### setCallback

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public 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 callback, Handler handler)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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.

Don't reuse the callback among the sessions. Callbacks keep internal reference to the session when it's set, so it may misbehave.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback callback` | The callback to receive updates on. |
| `https://developer.android.com/reference/android/os/Handler.html handler` | The handler that events should be posted on. |

### setCaptioningEnabled

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setCaptioningEnabled](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setCaptioningEnabled(boolean))(boolean enabled)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Enables/disables captioning for this session.

| Parameters |
|---|---|
| `boolean enabled` | `true` to enable captioning, `false` to disable. |

### setExtras

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setExtras](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setExtras(android.os.Bundle))(Bundle extras)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Sets some extras that can be associated with the `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat`. No assumptions should be made as to how a `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.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/os/Bundle.html extras` | The extras associated with the session. |

### setFlags

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setFlags](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setFlags(int))(int flags)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Sets any flags for the session.

| Parameters |
|---|---|
| `int flags` | The flags to set for this session. |

### setMediaButtonReceiver

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setMediaButtonReceiver](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setMediaButtonReceiver(android.app.PendingIntent))(PendingIntent mbr)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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 `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 `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.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/app/PendingIntent.html mbr` | The `https://developer.android.com/reference/android/app/PendingIntent.html` to send the media button event to. |

### setMetadata

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setMetadata](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setMetadata(android.support.v4.media.MediaMetadataCompat))(MediaMetadataCompat metadata)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Updates the current metadata. New metadata can be created using `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.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/MediaMetadataCompat metadata` | The new metadata |

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

### setPlaybackState

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setPlaybackState](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackState(android.support.v4.media.session.PlaybackStateCompat))(PlaybackStateCompat state)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Updates the current playback state.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/session/PlaybackStateCompat state` | The current state of playback |

### setPlaybackToLocal

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setPlaybackToLocal](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackToLocal(int))(int stream)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Sets the stream this session is playing on. This will affect the system's volume handling for this session. If `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackToRemote(androidx.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 `https://developer.android.com/reference/android/media/AudioManager.html#STREAM_MUSIC`.

| Parameters |
|---|---|
| `int stream` | The `https://developer.android.com/reference/android/media/AudioManager.html` stream this session is playing on. |

### setPlaybackToRemote

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setPlaybackToRemote](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackToRemote(androidx.media.VolumeProviderCompat))(VolumeProviderCompat volumeProvider)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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 `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 `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 `https://developer.android.com/reference/android/support/v4/media/session/MediaControllerCompat`. System routing of volume keys will not use the volume provider.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media/VolumeProviderCompat volumeProvider` | The provider that will handle volume changes. May not be null. |

### setQueue

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public 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> queue)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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. The id of each item should be unique within the play queue. 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.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.QueueItem> queue` | A list of items in the play queue. |

### setQueueTitle

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setQueueTitle](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setQueueTitle(java.lang.CharSequence))(CharSequence title)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence.html title` | The title of the play queue. |

### setRatingType

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setRatingType](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setRatingType(int))(int type)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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:

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

### setRepeatMode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setRepeatMode](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setRepeatMode(int))(int repeatMode)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Sets the repeat mode for this session.

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

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

### setSessionActivity

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setSessionActivity](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setSessionActivity(android.app.PendingIntent))(PendingIntent pi)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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 `https://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/app/PendingIntent.html pi` | The intent to launch to show UI for this Session. |

### setShuffleMode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [setShuffleMode](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setShuffleMode(int))(int shuffleMode)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Sets the shuffle mode for this session.

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

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