# DrmSessionManager

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/DrmSessionManager.java+class:androidx.media3.exoplayer.drm.DrmSessionManager)

*** ** * ** ***


```
@UnstableApi
public interface DrmSessionManager
```

<br />

Known direct subclasses [DefaultDrmSessionManager](https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DefaultDrmSessionManager` | 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`. |

*** ** * ** ***

Manages a DRM session.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager.DrmSessionReference` Represents a single reference count of a `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession`, while deliberately not giving access to the underlying session. |

| ### Constants |
|---|---|
| `default 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. |

| ### Public methods |
|---|---|
| `abstract @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/DrmSessionManager#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. |
| `abstract int` | `@https://developer.android.com/reference/androidx/media3/common/C.CryptoType https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#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`. |
| `default https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager.DrmSessionReference` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#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`. |
| `default void` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#prepare()()` Acquires any required resources. |
| `default void` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#release()()` Releases any acquired resources. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager#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. |

## Constants

### DRM_UNSUPPORTED

```
default static final DrmSessionManager DRM_UNSUPPORTED
```

An instance that supports no DRM schemes.

## Public methods

### acquireSession

```
abstract @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
abstract 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

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

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

```
default void release()
```

Releases any acquired resources.

### setPlayer

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