# DrmSession

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

*** ** * ** ***


```
@UnstableApi
public interface DrmSession
```

<br />

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

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/drm/ErrorStateDrmSession` | A `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession` that's in a terminal error state. |

*** ** * ** ***

A DRM session.

## Summary

| ### Nested types |
|---|
| `public class https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession.DrmSessionException extends https://developer.android.com/reference/java/io/IOException.html` Wraps the throwable which is the cause of the error state. |
| `@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/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession.State` The state of the DRM session. |

| ### Constants |
|---|---|
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_ERROR() = 1` The session has encountered an error. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_OPENED() = 3` The session is open, but does not have keys required for decryption. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_OPENED_WITH_KEYS() = 4` The session is open and has keys required for decryption. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_OPENING() = 2` The session is being opened. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_RELEASED() = 0` The session has been released. |

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#acquire(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher eventDispatcher )` Increments the reference count. |
| `abstract @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/decoder/CryptoConfig` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#getCryptoConfig()()` Returns a `https://developer.android.com/reference/androidx/media3/decoder/CryptoConfig` for the open session, or null if called before the session has been opened or after it's been released. |
| `abstract @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession.DrmSessionException` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#getError()()` Returns the cause of the error state, or null if `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#getState()` is not `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_ERROR()`. |
| `abstract @https://developer.android.com/reference/androidx/annotation/Nullable byte[]` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#getOfflineLicenseKeySetId()()` Returns the key set id of the offline license loaded into this session, or null if there isn't one. |
| `abstract https://developer.android.com/reference/java/util/UUID.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#getSchemeUuid()()` Returns the DRM scheme UUID for this session. |
| `abstract int` | `@https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession.State https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#getState()()` Returns the current state of the session, which is one of `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_ERROR()`, `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_RELEASED()`, `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_OPENING()`, `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_OPENED()` and `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_OPENED_WITH_KEYS()`. |
| `default boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#playClearSamplesWithoutKeys()()` Returns whether this session allows playback of clear samples prior to keys being loaded. |
| `abstract @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html>` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#queryKeyStatus()()` Returns a map describing the key status for the session, or null if called before the session has been opened or after it's been released. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#release(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher eventDispatcher )` Decrements the reference count. |
| `default static void` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#replaceSession(androidx.media3.exoplayer.drm.DrmSession,androidx.media3.exoplayer.drm.DrmSession)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession previousSession, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession newSession )` Acquires `newSession` then releases `previousSession`. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#requiresSecureDecoder(java.lang.String)(https://developer.android.com/reference/java/lang/String.html mimeType)` Returns whether this session requires use of a secure decoder for the given MIME type. |

## Constants

### STATE_ERROR

```
default static final int STATE_ERROR = 1
```

The session has encountered an error. `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#getError()` can be used to retrieve the cause. This is a terminal state.

### STATE_OPENED

```
default static final int STATE_OPENED = 3
```

The session is open, but does not have keys required for decryption.

### STATE_OPENED_WITH_KEYS

```
default static final int STATE_OPENED_WITH_KEYS = 4
```

The session is open and has keys required for decryption.

### STATE_OPENING

```
default static final int STATE_OPENING = 2
```

The session is being opened.

### STATE_RELEASED

```
default static final int STATE_RELEASED = 0
```

The session has been released. This is a terminal state.

## Public methods

### acquire

```
abstract void acquire(
    @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher
)
```

Increments the reference count. When the caller no longer needs to use the instance, 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.

| 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 route DRM-related events dispatched from this session, or null if no event handling is needed. |

### getCryptoConfig

```
abstract @Nullable CryptoConfig getCryptoConfig()
```

Returns a `https://developer.android.com/reference/androidx/media3/decoder/CryptoConfig` for the open session, or null if called before the session has been opened or after it's been released.

### getError

```
abstract @Nullable DrmSession.DrmSessionException getError()
```

Returns the cause of the error state, or null if `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#getState()` is not `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_ERROR()`.

### getOfflineLicenseKeySetId

```
abstract @Nullable byte[] getOfflineLicenseKeySetId()
```

Returns the key set id of the offline license loaded into this session, or null if there isn't one.

### getSchemeUuid

```
abstract UUID getSchemeUuid()
```

Returns the DRM scheme UUID for this session.

### getState

```
@DrmSession.State
abstract int getState()
```

Returns the current state of the session, which is one of `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_ERROR()`, `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_RELEASED()`, `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_OPENING()`, `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_OPENED()` and `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_OPENED_WITH_KEYS()`.

### playClearSamplesWithoutKeys

```
default boolean playClearSamplesWithoutKeys()
```

Returns whether this session allows playback of clear samples prior to keys being loaded.

### queryKeyStatus

```
abstract @Nullable Map<String, String> queryKeyStatus()
```

Returns a map describing the key status for the session, or null if called before the session has been opened or after it's been released.

Since DRM license policies vary by vendor, the specific status field names are determined by each DRM vendor. Refer to your DRM provider documentation for definitions of the field names for a particular DRM engine plugin.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html>` | A map describing the key status for the session, or null if called before the session has been opened or after it's been released. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaDrm.html#queryKeyStatus(byte[])` |   |

### release

```
abstract void release(
    @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher
)
```

Decrements the reference count. If the reference count drops to 0 underlying resources are released, and the instance cannot be re-used.

| 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` to disconnect when the session is released (the same instance (possibly null) that was passed by the caller to `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#acquire(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)`). |

### replaceSession

```
default static void replaceSession(
    @Nullable DrmSession previousSession,
    @Nullable DrmSession newSession
)
```

Acquires `newSession` then releases `previousSession`.

Invokes `newSession's``https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#acquire(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)` and `previousSession's``https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#release(androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)` in that order (passing `eventDispatcher = null`). Null arguments are ignored. Does nothing if `previousSession` and `newSession` are the same session.

### requiresSecureDecoder

```
abstract boolean requiresSecureDecoder(String mimeType)
```

Returns whether this session requires use of a secure decoder for the given MIME type. Assumes a license policy that requires the highest level of security supported by the session.

The session must be in `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#getState()``https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_OPENED()` or `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession#STATE_OPENED_WITH_KEYS()`.