# OfflineLicenseHelper

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

*** ** * ** ***

<br />

```
@UnstableApi
class OfflineLicenseHelper
```

<br />

*** ** * ** ***

Helper class to download, renew and release offline licenses.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#OfflineLicenseHelper(androidx.media3.exoplayer.drm.DefaultDrmSessionManager,androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)( defaultDrmSessionManager: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DefaultDrmSessionManager!, eventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher! )` Constructs an instance. |

| ### Public functions |
|---|---|
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#downloadLicense(androidx.media3.common.Format)(format: https://developer.android.com/reference/kotlin/androidx/media3/common/Format!)` Downloads an offline license. |
| `synchronized https://developer.android.com/reference/android/util/Pair.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#getLicenseDurationRemainingSec(byte[])(offlineLicenseKeySetId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` Returns the remaining license and playback durations in seconds, for an offline license. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#newWidevineInstance(java.lang.String,androidx.media3.datasource.DataSource.Factory,androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)( defaultLicenseUrl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, dataSourceFactory: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory!, eventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher! )` Instantiates a new instance which uses Widevine CDM. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#newWidevineInstance(androidx.media3.common.MediaItem.DrmConfiguration,androidx.media3.datasource.DataSource.Factory,androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)( drmConfiguration: https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem.DrmConfiguration!, dataSourceFactory: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory!, eventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher! )` Instantiates a new instance which uses Widevine CDM. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#newWidevineInstance(java.lang.String,boolean,androidx.media3.datasource.DataSource.Factory,androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)( defaultLicenseUrl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, forceDefaultLicenseUrl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, dataSourceFactory: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory!, eventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher! )` Instantiates a new instance which uses Widevine CDM. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#newWidevineInstance(java.lang.String,boolean,androidx.media3.datasource.DataSource.Factory,java.util.Map<java.lang.String,java.lang.String>,androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher)( defaultLicenseUrl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, forceDefaultLicenseUrl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, dataSourceFactory: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory!, optionalKeyRequestParameters: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>?, eventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher! )` Instantiates a new instance which uses Widevine CDM. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#release()()` Releases the helper. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#releaseLicense(byte[])(offlineLicenseKeySetId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` Releases an offline license. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#renewLicense(byte[])(offlineLicenseKeySetId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` Renews an offline license. |

## Public constructors

### OfflineLicenseHelper

```
OfflineLicenseHelper(
    defaultDrmSessionManager: DefaultDrmSessionManager!,
    eventDispatcher: DrmSessionEventListener.EventDispatcher!
)
```

Constructs an instance. Call `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#release()` when the instance is no longer required.

| Parameters |
|---|---|
| `defaultDrmSessionManager: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DefaultDrmSessionManager!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DefaultDrmSessionManager` used to download licenses. |
| `eventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher!` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher` used to distribute DRM-related events. |

## Public functions

### downloadLicense

```
synchronized fun downloadLicense(format: Format!): Array<Byte>!
```

Downloads an offline license.

| Parameters |
|---|---|
| `format: https://developer.android.com/reference/kotlin/androidx/media3/common/Format!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/Format` of the content whose license is to be downloaded. Must contain a non-null `https://developer.android.com/reference/kotlin/androidx/media3/common/Format#drmInitData()`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The key set id for the downloaded license. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSession.DrmSessionException` | Thrown when a DRM session error occurs. |

### getLicenseDurationRemainingSec

```
synchronized fun getLicenseDurationRemainingSec(offlineLicenseKeySetId: ByteArray<Byte>!): Pair<Long!, Long!>!
```

Returns the remaining license and playback durations in seconds, for an offline license.

| Parameters |
|---|---|
| `offlineLicenseKeySetId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The key set id of the license. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/util/Pair.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html!>!` | The remaining license and playback durations, in seconds. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSession.DrmSessionException` | Thrown when a DRM session error occurs. |

### newWidevineInstance

```
java-static fun newWidevineInstance(
    defaultLicenseUrl: String!,
    dataSourceFactory: DataSource.Factory!,
    eventDispatcher: DrmSessionEventListener.EventDispatcher!
): OfflineLicenseHelper!
```

Instantiates a new instance which uses Widevine CDM. Call `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#release()` when the instance is no longer required.

| Parameters |
|---|---|
| `defaultLicenseUrl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The default license URL. Used for key requests that do not specify their own license URL. |
| `dataSourceFactory: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory!` | A factory from which to obtain `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` instances. |
| `eventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher!` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher` used to distribute DRM-related events. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper!` | A new instance which uses Widevine CDM. |

### newWidevineInstance

```
java-static fun newWidevineInstance(
    drmConfiguration: MediaItem.DrmConfiguration!,
    dataSourceFactory: DataSource.Factory!,
    eventDispatcher: DrmSessionEventListener.EventDispatcher!
): OfflineLicenseHelper!
```

Instantiates a new instance which uses Widevine CDM. Call `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#release()` when the instance is no longer required.

| Parameters |
|---|---|
| `drmConfiguration: https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem.DrmConfiguration!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem.DrmConfiguration` specifying the request details. Must use `https://developer.android.com/reference/kotlin/androidx/media3/common/C#WIDEVINE_UUID()` as `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem.DrmConfiguration#scheme()` and contain a non-null `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem.DrmConfiguration#licenseUri()`. |
| `dataSourceFactory: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory!` | A factory from which to obtain `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` instances. |
| `eventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher!` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher` used to distribute DRM-related events. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper!` | A new instance which uses Widevine CDM. |

### newWidevineInstance

```
java-static fun newWidevineInstance(
    defaultLicenseUrl: String!,
    forceDefaultLicenseUrl: Boolean,
    dataSourceFactory: DataSource.Factory!,
    eventDispatcher: DrmSessionEventListener.EventDispatcher!
): OfflineLicenseHelper!
```

Instantiates a new instance which uses Widevine CDM. Call `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#release()` when the instance is no longer required.

| Parameters |
|---|---|
| `defaultLicenseUrl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The default license URL. Used for key requests that do not specify their own license URL. |
| `forceDefaultLicenseUrl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether to use `defaultLicenseUrl` for key requests that include their own license URL. |
| `dataSourceFactory: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory!` | A factory from which to obtain `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` instances. |
| `eventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher!` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher` used to distribute DRM-related events. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper!` | A new instance which uses Widevine CDM. |

### newWidevineInstance

```
java-static fun newWidevineInstance(
    defaultLicenseUrl: String!,
    forceDefaultLicenseUrl: Boolean,
    dataSourceFactory: DataSource.Factory!,
    optionalKeyRequestParameters: (Mutable)Map<String!, String!>?,
    eventDispatcher: DrmSessionEventListener.EventDispatcher!
): OfflineLicenseHelper!
```

Instantiates a new instance which uses Widevine CDM. Call `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper#release()` when the instance is no longer required.

| Parameters |
|---|---|
| `defaultLicenseUrl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The default license URL. Used for key requests that do not specify their own license URL. |
| `forceDefaultLicenseUrl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether to use `defaultLicenseUrl` for key requests that include their own license URL. |
| `dataSourceFactory: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory!` | A factory from which to obtain `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` instances. |
| `optionalKeyRequestParameters: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>?` | An optional map of parameters to pass as the last argument to `https://developer.android.com/reference/android/media/MediaDrm.html#getKeyRequest(byte[], byte[], java.lang.String, int, java.util.HashMap&lt;java.lang.String,java.lang.String&gt;)`. May be null. |
| `eventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher!` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher` used to distribute DRM-related events. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/OfflineLicenseHelper!` | A new instance which uses Widevine CDM. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.Builder` |   |

### release

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

Releases the helper. Should be called when the helper is no longer required.

### releaseLicense

```
synchronized fun releaseLicense(offlineLicenseKeySetId: ByteArray<Byte>!): Unit
```

Releases an offline license.

| Parameters |
|---|---|
| `offlineLicenseKeySetId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The key set id of the license to be released. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSession.DrmSessionException` | Thrown when a DRM session error occurs. |

### renewLicense

```
synchronized fun renewLicense(offlineLicenseKeySetId: ByteArray<Byte>!): Array<Byte>!
```

Renews an offline license.

| Parameters |
|---|---|
| `offlineLicenseKeySetId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The key set id of the license to be renewed. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The renewed offline license key set id. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSession.DrmSessionException` | Thrown when a DRM session error occurs. |