OfflineLicenseHelper


@UnstableApi
public final class OfflineLicenseHelper


Helper class to download, renew and release offline licenses.

Summary

Public constructors

OfflineLicenseHelper(
    DefaultDrmSessionManager defaultDrmSessionManager,
    DrmSessionEventListener.EventDispatcher eventDispatcher
)

Constructs an instance.

Public methods

synchronized byte[]

Downloads an offline license.

synchronized Pair<LongLong>
getLicenseDurationRemainingSec(byte[] offlineLicenseKeySetId)

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

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

Instantiates a new instance which uses Widevine CDM.

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,
    @Nullable Map<StringString> optionalKeyRequestParameters,
    DrmSessionEventListener.EventDispatcher eventDispatcher
)

Instantiates a new instance which uses Widevine CDM.

void

Releases the helper.

synchronized void
releaseLicense(byte[] offlineLicenseKeySetId)

Releases an offline license.

synchronized byte[]
renewLicense(byte[] offlineLicenseKeySetId)

Renews an offline license.

Public constructors

OfflineLicenseHelper

public OfflineLicenseHelper(
    DefaultDrmSessionManager defaultDrmSessionManager,
    DrmSessionEventListener.EventDispatcher eventDispatcher
)

Constructs an instance. Call release when the instance is no longer required.

Parameters
DefaultDrmSessionManager defaultDrmSessionManager

The DefaultDrmSessionManager used to download licenses.

DrmSessionEventListener.EventDispatcher eventDispatcher

A DrmSessionEventListener.EventDispatcher used to distribute DRM-related events.

Public methods

downloadLicense

synchronized public byte[] downloadLicense(Format format)

Downloads an offline license.

Parameters
Format format

The Format of the content whose license is to be downloaded. Must contain a non-null drmInitData.

Returns
byte[]

The key set id for the downloaded license.

Throws
androidx.media3.exoplayer.drm.DrmSession.DrmSessionException

Thrown when a DRM session error occurs.

getLicenseDurationRemainingSec

synchronized public Pair<LongLonggetLicenseDurationRemainingSec(byte[] offlineLicenseKeySetId)

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

Parameters
byte[] offlineLicenseKeySetId

The key set id of the license.

Returns
Pair<LongLong>

The remaining license and playback durations, in seconds.

Throws
androidx.media3.exoplayer.drm.DrmSession.DrmSessionException

Thrown when a DRM session error occurs.

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
String defaultLicenseUrl

The default license URL. Used for key requests that do not specify their own license URL.

DataSource.Factory dataSourceFactory

A factory from which to obtain DataSource instances.

DrmSessionEventListener.EventDispatcher eventDispatcher

A DrmSessionEventListener.EventDispatcher used to distribute DRM-related events.

Returns
OfflineLicenseHelper

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
String defaultLicenseUrl

The default license URL. Used for key requests that do not specify their own license URL.

boolean forceDefaultLicenseUrl

Whether to use defaultLicenseUrl for key requests that include their own license URL.

DataSource.Factory dataSourceFactory

A factory from which to obtain DataSource instances.

DrmSessionEventListener.EventDispatcher eventDispatcher

A DrmSessionEventListener.EventDispatcher used to distribute DRM-related events.

Returns
OfflineLicenseHelper

A new instance which uses Widevine CDM.

newWidevineInstance

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

Instantiates a new instance which uses Widevine CDM. Call release when the instance is no longer required.

Parameters
String defaultLicenseUrl

The default license URL. Used for key requests that do not specify their own license URL.

boolean forceDefaultLicenseUrl

Whether to use defaultLicenseUrl for key requests that include their own license URL.

DataSource.Factory dataSourceFactory

A factory from which to obtain DataSource instances.

@Nullable Map<StringString> optionalKeyRequestParameters

An optional map of parameters to pass as the last argument to getKeyRequest. May be null.

DrmSessionEventListener.EventDispatcher eventDispatcher

A DrmSessionEventListener.EventDispatcher used to distribute DRM-related events.

Returns
OfflineLicenseHelper

A new instance which uses Widevine CDM.

release

public void release()

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

releaseLicense

synchronized public void releaseLicense(byte[] offlineLicenseKeySetId)

Releases an offline license.

Parameters
byte[] offlineLicenseKeySetId

The key set id of the license to be released.

Throws
androidx.media3.exoplayer.drm.DrmSession.DrmSessionException

Thrown when a DRM session error occurs.

renewLicense

synchronized public byte[] renewLicense(byte[] offlineLicenseKeySetId)

Renews an offline license.

Parameters
byte[] offlineLicenseKeySetId

The key set id of the license to be renewed.

Returns
byte[]

The renewed offline license key set id.

Throws
androidx.media3.exoplayer.drm.DrmSession.DrmSessionException

Thrown when a DRM session error occurs.