Package com.google.android.exoplayer2.drm

## Class OfflineLicenseHelper

- java.lang.Object
- - com.google.android.exoplayer2.drm.OfflineLicenseHelper

-     @RequiresApi(18)
      public final class OfflineLicenseHelper
      extends Object

  Helper class to download, renew and release offline licenses.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `OfflineLicenseHelper​(DefaultDrmSessionManager defaultDrmSessionManager, DrmSessionEventListener.EventDispatcher eventDispatcher)` | Constructs an instance.
    `OfflineLicenseHelper​(UUID uuid, ExoMediaDrm.Provider mediaDrmProvider, MediaDrmCallback callback, Map<String,​String> optionalKeyRequestParameters, DrmSessionEventListener.EventDispatcher eventDispatcher)` | Deprecated. Use `OfflineLicenseHelper(DefaultDrmSessionManager, DrmSessionEventListener.EventDispatcher)` instead.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `byte[]` | `downloadLicense​(Format format)` | Downloads an offline license.
    `Pair<Long,​Long>` | `getLicenseDurationRemainingSec​(byte[] offlineLicenseKeySetId)` | Returns the remaining license and playback durations in seconds, for an offline license.
    `static OfflineLicenseHelper` | `newWidevineInstance​(String defaultLicenseUrl, boolean forceDefaultLicenseUrl, DataSource.Factory dataSourceFactory, DrmSessionEventListener.EventDispatcher eventDispatcher)` | Instantiates a new instance which uses Widevine CDM.
    `static OfflineLicenseHelper` | `newWidevineInstance​(String defaultLicenseUrl, boolean forceDefaultLicenseUrl, DataSource.Factory dataSourceFactory, Map<String,​String> optionalKeyRequestParameters, DrmSessionEventListener.EventDispatcher eventDispatcher)` | Instantiates a new instance which uses Widevine CDM.
    `static OfflineLicenseHelper` | `newWidevineInstance​(String defaultLicenseUrl, DataSource.Factory dataSourceFactory, DrmSessionEventListener.EventDispatcher eventDispatcher)` | Instantiates a new instance which uses Widevine CDM.
    `void` | `release()` | Releases the helper.
    `void` | `releaseLicense​(byte[] offlineLicenseKeySetId)` | Releases an offline license.
    `byte[]` | `renewLicense​(byte[] offlineLicenseKeySetId)` | Renews an offline license.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### OfflineLicenseHelper

          @Deprecated
          public OfflineLicenseHelper​(UUID uuid,
                                      ExoMediaDrm.Provider mediaDrmProvider,
                                      MediaDrmCallback callback,
                                      @Nullable
                                      Map<String,​String> optionalKeyRequestParameters,
                                      DrmSessionEventListener.EventDispatcher eventDispatcher)

      Deprecated.
      Use `OfflineLicenseHelper(DefaultDrmSessionManager, DrmSessionEventListener.EventDispatcher)` instead.

    - #### OfflineLicenseHelper

          public OfflineLicenseHelper​(DefaultDrmSessionManager defaultDrmSessionManager,
                                      DrmSessionEventListener.EventDispatcher eventDispatcher)

      Constructs an instance. Call `release()` when the instance is no longer required.
      Parameters:
        `defaultDrmSessionManager` - The `DefaultDrmSessionManager` used to download licenses.
        `eventDispatcher` - A `DrmSessionEventListener.EventDispatcher` used to distribute DRM-related events.

  - ### Method Detail

    - #### newWidevineInstance

          public static OfflineLicenseHelper newWidevineInstance​(String defaultLicenseUrl,
                                                                 DataSource.Factory dataSourceFactory,
                                                                 DrmSessionEventListener.EventDispatcher eventDispatcher)

      Instantiates a new instance which uses Widevine CDM. Call `release()` when the instance is no longer required.
      Parameters:
        `defaultLicenseUrl` - The default license URL. Used for key requests that do not specify their own license URL.
        `dataSourceFactory` - A factory from which to obtain `DataSource` instances.
        `eventDispatcher` - A `DrmSessionEventListener.EventDispatcher` used to distribute DRM-related events.
      Returns:
        A new instance which uses Widevine CDM.

    - #### newWidevineInstance

          public static OfflineLicenseHelper newWidevineInstance​(String defaultLicenseUrl,
                                                                 boolean forceDefaultLicenseUrl,
                                                                 DataSource.Factory dataSourceFactory,
                                                                 DrmSessionEventListener.EventDispatcher eventDispatcher)

      Instantiates a new instance which uses Widevine CDM. Call `release()` when the instance is no longer required.
      Parameters:
        `defaultLicenseUrl` - The default license URL. Used for key requests that do not specify their own license URL.
        `forceDefaultLicenseUrl` - Whether to use `defaultLicenseUrl` for key requests that include their own license URL.
        `dataSourceFactory` - A factory from which to obtain `DataSource` instances.
        `eventDispatcher` - A `DrmSessionEventListener.EventDispatcher` used to distribute DRM-related events.
      Returns:
        A new instance which uses Widevine CDM.

    - #### newWidevineInstance

          public static OfflineLicenseHelper newWidevineInstance​(String defaultLicenseUrl,
                                                                 boolean forceDefaultLicenseUrl,
                                                                 DataSource.Factory dataSourceFactory,
                                                                 @Nullable
                                                                 Map<String,​String> optionalKeyRequestParameters,
                                                                 DrmSessionEventListener.EventDispatcher eventDispatcher)

      Instantiates a new instance which uses Widevine CDM. Call `release()` when the instance is no longer required.
      Parameters:
        `defaultLicenseUrl` - The default license URL. Used for key requests that do not specify their own license URL.
        `forceDefaultLicenseUrl` - Whether to use `defaultLicenseUrl` for key requests that include their own license URL.
        `optionalKeyRequestParameters` - An optional map of parameters to pass as the last argument to `MediaDrm.getKeyRequest(byte[], byte[], java.lang.String, int, java.util.HashMap<java.lang.String, java.lang.String>)`. May be null.
        `eventDispatcher` - A `DrmSessionEventListener.EventDispatcher` used to distribute DRM-related events.
      Returns:
        A new instance which uses Widevine CDM.
      See Also:
        `DefaultDrmSessionManager.Builder`

    - #### downloadLicense

          public byte[] downloadLicense​(Format format)
                                 throws DrmSession.DrmSessionException

      Downloads an offline license.
      Parameters:
        `format` - The `Format` of the content whose license is to be downloaded. Must contain a non-null `Format.drmInitData`.
      Returns:
        The key set id for the downloaded license.
      Throws:
        `DrmSession.DrmSessionException` - Thrown when a DRM session error occurs.

    - #### renewLicense

          public byte[] renewLicense​(byte[] offlineLicenseKeySetId)
                              throws DrmSession.DrmSessionException

      Renews an offline license.
      Parameters:
        `offlineLicenseKeySetId` - The key set id of the license to be renewed.
      Returns:
        The renewed offline license key set id.
      Throws:
        `DrmSession.DrmSessionException` - Thrown when a DRM session error occurs.

    - #### releaseLicense

          public void releaseLicense​(byte[] offlineLicenseKeySetId)
                              throws DrmSession.DrmSessionException

      Releases an offline license.
      Parameters:
        `offlineLicenseKeySetId` - The key set id of the license to be released.
      Throws:
        `DrmSession.DrmSessionException` - Thrown when a DRM session error occurs.

    - #### getLicenseDurationRemainingSec

          public Pair<Long,​Long> getLicenseDurationRemainingSec​(byte[] offlineLicenseKeySetId)
                                                               throws DrmSession.DrmSessionException

      Returns the remaining license and playback durations in seconds, for an offline license.
      Parameters:
        `offlineLicenseKeySetId` - The key set id of the license.
      Returns:
        The remaining license and playback durations, in seconds.
      Throws:
        `DrmSession.DrmSessionException` - Thrown when a DRM session error occurs.

    - #### release

          public void release()

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