# DrmSessionManager

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager "View this page in Java")

<br />

```
@UnstableApi
interface DrmSessionManager
```

<br />

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

|-----------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DefaultDrmSessionManager](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DefaultDrmSessionManager) | A[DrmSessionManager](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager)that supports playbacks using[ExoMediaDrm](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/ExoMediaDrm). |

*** ** * ** ***

Manages a DRM session.

## Summary

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

|                                                         ### Constants                                                          |
|--------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[DrmSessionManager](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager)`!` | [DRM_UNSUPPORTED](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager#DRM_UNSUPPORTED()) An instance that supports no DRM schemes. |

|                                                                      ### Public functions                                                                      |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DrmSession](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSession)`?`                                                       | [acquireSession](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager#acquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format))`(` ` eventDispatcher: `[DrmSessionEventListener.EventDispatcher](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher)`?,` ` format: `[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!` `)` Returns a[DrmSession](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSession)for the specified[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format), with an incremented reference count. |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                    | `@`[C.CryptoType](https://developer.android.com/reference/kotlin/androidx/media3/common/C.CryptoType) [getCryptoType](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager#getCryptoType(androidx.media3.common.Format))`(format: `[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!)` Returns the[C.CryptoType](https://developer.android.com/reference/kotlin/androidx/media3/common/C.CryptoType)that the DRM session manager will use for a given[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format).                                                                                                                                                                        |
| [DrmSessionManager.DrmSessionReference](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager.DrmSessionReference)`!` | [preacquireSession](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager#preacquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format))`(` ` eventDispatcher: `[DrmSessionEventListener.EventDispatcher](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher)`?,` ` format: `[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!` `)` Pre-acquires a DRM session for the specified[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format).                                                                                                                   |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                  | [prepare](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager#prepare())`()` Acquires any required resources.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                  | [release](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager#release())`()` Releases any acquired resources.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                  | [setPlayer](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager#setPlayer(android.os.Looper,androidx.media3.exoplayer.analytics.PlayerId))`(playbackLooper: `[Looper](https://developer.android.com/reference/android/os/Looper.html)`!, playerId: `[PlayerId](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/analytics/PlayerId)`!)` Sets information about the player using this DRM session manager.                                                                                                                                                                                                                                                                                                                         |

## Constants

### DRM_UNSUPPORTED

```
const val DRM_UNSUPPORTED: DrmSessionManager!
```

An instance that supports no DRM schemes.  

## Public functions

### acquireSession

```
fun acquireSession(
    eventDispatcher: DrmSessionEventListener.EventDispatcher?,
    format: Format!
): DrmSession?
```

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

If the provided[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)contains a null[drmInitData](https://developer.android.com/reference/kotlin/androidx/media3/common/Format#drmInitData()), the returned[DrmSession](https://developer.android.com/reference/kotlin/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                                                                                       |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `eventDispatcher: `[DrmSessionEventListener.EventDispatcher](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher)`?` | The[DrmSessionEventListener.EventDispatcher](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher)used to distribute events, and passed on to[acquire](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSession#acquire(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)). |
| `format: `[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!`                                                                                   | The[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)for which to acquire a[DrmSession](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSession).                                                                                                                                                                           |

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

### getCryptoType

```
@C.CryptoType
fun getCryptoType(format: Format!): Int
```

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

|                                             Parameters                                              |
|-----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
| `format: `[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!` | The[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format). |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The[C.CryptoType](https://developer.android.com/reference/kotlin/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[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format). Will be[CRYPTO_TYPE_NONE](https://developer.android.com/reference/kotlin/androidx/media3/common/C#CRYPTO_TYPE_NONE())if[drmInitData](https://developer.android.com/reference/kotlin/androidx/media3/common/Format#drmInitData())is null and[acquireSession](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager#acquireSession(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format))will return null for the given[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format). |

### preacquireSession

```
fun preacquireSession(
    eventDispatcher: DrmSessionEventListener.EventDispatcher?,
    format: Format!
): DrmSessionManager.DrmSessionReference!
```

Pre-acquires a DRM session for the specified[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format).

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

The caller must call[release](https://developer.android.com/reference/kotlin/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[acquireSession](https://developer.android.com/reference/kotlin/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[acquireSession](https://developer.android.com/reference/kotlin/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[acquireSession](https://developer.android.com/reference/kotlin/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[DrmSessionReference](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager.DrmSessionReference)and full[DrmSession](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSession)instances are distinct. The caller must release both, and can release the[DrmSessionReference](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager.DrmSessionReference)before the[DrmSession](https://developer.android.com/reference/kotlin/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[DrmSessionReference](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager.DrmSessionReference)instance.  

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

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

### prepare

```
fun prepare(): Unit
```

Acquires any required resources.

[release](https://developer.android.com/reference/kotlin/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

```
fun release(): Unit
```

Releases any acquired resources.  

### setPlayer

```
fun setPlayer(playbackLooper: Looper!, playerId: PlayerId!): Unit
```

Sets information about the player using this DRM session manager.  

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