# DefaultDrmSessionManager

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/drm/DefaultDrmSessionManager.java+class:androidx.media3.exoplayer.drm.DefaultDrmSessionManager)

*** ** * ** ***

<br />

```
@UnstableApi
public class DefaultDrmSessionManager implements DrmSessionManager
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager` that supports playbacks using `https://developer.android.com/reference/androidx/media3/exoplayer/drm/ExoMediaDrm`.

This implementation supports pre-acquisition of sessions using `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#preacquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format)`.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.Builder` Builder for `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager` instances. |
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.MissingSchemeDataException extends https://developer.android.com/reference/java/lang/Exception.html` Signals that the `https://developer.android.com/reference/androidx/media3/common/Format#drmInitData()` passed to `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#acquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format)` does not contain scheme data for the required UUID. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.Mode` Determines the action to be done after a session acquired. |

| ### Constants |
|---|---|
| `static final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#DEFAULT_SESSION_KEEPALIVE_MS() = 300000` Default value for `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.Builder#setSessionKeepaliveMs(long)`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#INITIAL_DRM_REQUEST_RETRY_COUNT() = 3` Number of times to retry for initial provisioning and key request for reporting error. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#MODE_DOWNLOAD() = 2` Downloads an offline license or renews an existing one. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#MODE_PLAYBACK() = 0` Loads and refreshes (if necessary) a license for playback. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#MODE_QUERY() = 1` Restores an offline license to allow its status to be queried. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#MODE_RELEASE() = 3` Releases an existing offline license. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#PLAYREADY_CUSTOM_DATA_KEY() = "PRCustomData"` A key for specifying PlayReady custom data in the key request parameters passed to `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.Builder#setKeyRequestParameters(java.util.Map<java.lang.String,java.lang.String>)`. |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#acquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher eventDispatcher, https://developer.android.com/reference/androidx/media3/common/Format format )` Returns a `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession` for the specified `https://developer.android.com/reference/androidx/media3/common/Format`, with an incremented reference count. |
| `int` | `@https://developer.android.com/reference/androidx/media3/common/C.CryptoType https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#getCryptoType(androidx.media3.common.Format)(https://developer.android.com/reference/androidx/media3/common/Format format)` Returns the `https://developer.android.com/reference/androidx/media3/common/C.CryptoType` that the DRM session manager will use for a given `https://developer.android.com/reference/androidx/media3/common/Format`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager.DrmSessionReference` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#preacquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher eventDispatcher, https://developer.android.com/reference/androidx/media3/common/Format format )` Pre-acquires a DRM session for the specified `https://developer.android.com/reference/androidx/media3/common/Format`. |
| `final void` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#prepare()()` Acquires any required resources. |
| `final void` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#release()()` Releases any acquired resources. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#setMode(int,byte[])( @https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.Mode int mode, @https://developer.android.com/reference/androidx/annotation/Nullable byte[] offlineLicenseKeySetId )` Sets the mode, which determines the role of sessions acquired from the instance. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#setPlayer(android.os.Looper,androidx.media3.exoplayer.analytics.PlayerId)(https://developer.android.com/reference/android/os/Looper.html playbackLooper, https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId playerId)` Sets information about the player using this DRM session manager. |

### Inherited Constants

From [androidx.media3.exoplayer.drm.DrmSessionManager](https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager) `static final https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager` `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#DRM_UNSUPPORTED()`

An instance that supports no DRM schemes.

## Constants

### DEFAULT_SESSION_KEEPALIVE_MS

```
public static final long DEFAULT_SESSION_KEEPALIVE_MS = 300000
```

Default value for `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.Builder#setSessionKeepaliveMs(long)`.

### INITIAL_DRM_REQUEST_RETRY_COUNT

```
public static final int INITIAL_DRM_REQUEST_RETRY_COUNT = 3
```

Number of times to retry for initial provisioning and key request for reporting error.

### MODE_DOWNLOAD

```
public static final int MODE_DOWNLOAD = 2
```

Downloads an offline license or renews an existing one.

### MODE_PLAYBACK

```
public static final int MODE_PLAYBACK = 0
```

Loads and refreshes (if necessary) a license for playback. Supports streaming and offline licenses.

### MODE_QUERY

```
public static final int MODE_QUERY = 1
```

Restores an offline license to allow its status to be queried.

### MODE_RELEASE

```
public static final int MODE_RELEASE = 3
```

Releases an existing offline license.

### PLAYREADY_CUSTOM_DATA_KEY

```
public static final String PLAYREADY_CUSTOM_DATA_KEY = "PRCustomData"
```

A key for specifying PlayReady custom data in the key request parameters passed to `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.Builder#setKeyRequestParameters(java.util.Map<java.lang.String,java.lang.String>)`.

## Public methods

### acquireSession

```
public @Nullable DrmSession acquireSession(
    @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher,
    Format format
)
```

Returns a `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession` for the specified `https://developer.android.com/reference/androidx/media3/common/Format`, with an incremented reference count. May return null if the `https://developer.android.com/reference/androidx/media3/common/Format#drmInitData()` is null and the DRM session manager is not configured to attach a `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession` to clear content. When the caller no longer needs to use a returned `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession`, it must call `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#release(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)` to decrement the reference count.

If the provided `https://developer.android.com/reference/androidx/media3/common/Format` contains a null `https://developer.android.com/reference/androidx/media3/common/Format#drmInitData()`, the returned `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession` (if not null) will be a placeholder session which does not execute key requests, and cannot be used to handle encrypted content. However, a placeholder session may be used to configure secure decoders for playback of clear content periods, which can reduce the cost of transitioning between clear and encrypted content.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher eventDispatcher` | The `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher` used to distribute events, and passed on to `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#acquire(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)`. |
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The `https://developer.android.com/reference/androidx/media3/common/Format` for which to acquire a `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession` | The DRM session. May be null if the given `https://developer.android.com/reference/androidx/media3/common/Format#drmInitData()` is null. |

### getCryptoType

```
@C.CryptoType
public int getCryptoType(Format format)
```

Returns the `https://developer.android.com/reference/androidx/media3/common/C.CryptoType` that the DRM session manager will use for a given `https://developer.android.com/reference/androidx/media3/common/Format`. Returns `https://developer.android.com/reference/androidx/media3/common/C#CRYPTO_TYPE_UNSUPPORTED()` if the manager does not support any of the DRM schemes defined in the `https://developer.android.com/reference/androidx/media3/common/Format`. Returns `https://developer.android.com/reference/androidx/media3/common/C#CRYPTO_TYPE_NONE()` if `https://developer.android.com/reference/androidx/media3/common/Format#drmInitData()` is null and `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#acquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format)` will return `null` for the given `https://developer.android.com/reference/androidx/media3/common/Format`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The `https://developer.android.com/reference/androidx/media3/common/Format`. |

| Returns |
|---|---|
| `int` | The `https://developer.android.com/reference/androidx/media3/common/C.CryptoType` that the manager will use, or @link C#CRYPTO_TYPE_UNSUPPORTED} if the manager does not support any of the DRM schemes defined in the `https://developer.android.com/reference/androidx/media3/common/Format`. Will be `https://developer.android.com/reference/androidx/media3/common/C#CRYPTO_TYPE_NONE()` if `https://developer.android.com/reference/androidx/media3/common/Format#drmInitData()` is null and `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#acquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format)` will return null for the given `https://developer.android.com/reference/androidx/media3/common/Format`. |

### preacquireSession

```
public DrmSessionManager.DrmSessionReference preacquireSession(
    @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher,
    Format format
)
```

Pre-acquires a DRM session for the specified `https://developer.android.com/reference/androidx/media3/common/Format`.

This notifies the manager that a subsequent call to `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#acquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format)` with the same `https://developer.android.com/reference/androidx/media3/common/Format` is likely, allowing a manager that supports pre-acquisition to get the required `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession` ready in the background.

The caller must call `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager.DrmSessionReference#release()` on the returned instance when they no longer require the pre-acquisition (i.e. they know they won't be making a matching call to `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#acquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format)` in the near future).

This manager may silently release the underlying session in order to allow another operation to complete. This will result in a subsequent call to `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#acquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format)` re-initializing a new session, including repeating key loads and other async initialization steps.

The caller must separately call `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#acquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format)` in order to obtain a session suitable for playback. The pre-acquired `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager.DrmSessionReference` and full `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession` instances are distinct. The caller must release both, and can release the `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager.DrmSessionReference` before the `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession` without affecting playback.

This can be called from any thread.

Implementations that do not support pre-acquisition always return an empty `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager.DrmSessionReference` instance.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher eventDispatcher` | The `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher` used to distribute events, and passed on to `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#acquire(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)`. |
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The `https://developer.android.com/reference/androidx/media3/common/Format` for which to pre-acquire a `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager.DrmSessionReference` | A releaser for the pre-acquired session. Guaranteed to be non-null even if the matching `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#acquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format)` would return null. |

### prepare

```
public final void prepare()
```

Acquires any required resources.

`https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#release()` must be called to ensure the acquired resources are released. After releasing, an instance may be re-prepared.

### release

```
public final void release()
```

Releases any acquired resources.

### setMode

```
public void setMode(
    @DefaultDrmSessionManager.Mode int mode,
    @Nullable byte[] offlineLicenseKeySetId
)
```

Sets the mode, which determines the role of sessions acquired from the instance. This must be called before `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#acquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format)` is called.

By default, the mode is `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#MODE_PLAYBACK()` and a streaming license is requested when required.

`mode` must be one of these:

- `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#MODE_PLAYBACK()`: If `offlineLicenseKeySetId` is null then a streaming license is requested. Otherwise, the offline license is restored.
- `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#MODE_QUERY()`: `offlineLicenseKeySetId` cannot be null. The offline license is restored to allow its status to be queried.
- `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#MODE_DOWNLOAD()`: If `offlineLicenseKeySetId` is null then an offline license is requested. Otherwise, the offline license is renewed.
- `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager#MODE_RELEASE()`: `offlineLicenseKeySetId` cannot be null. The offline license is released.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.Mode int mode` | The mode to be set. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable byte[] offlineLicenseKeySetId` | The key set id of the license to be used with the given mode. |

### setPlayer

```
public void setPlayer(Looper playbackLooper, PlayerId playerId)
```

Sets information about the player using this DRM session manager.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/os/Looper.html playbackLooper` | The `https://developer.android.com/reference/android/os/Looper.html` associated with the player's playback thread. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId playerId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId` of the player. |