DefaultDrmSessionManager


@RequiresApi(value = 18)
@UnstableApi
public class DefaultDrmSessionManager implements DrmSessionManager


A DrmSessionManager that supports playbacks using ExoMediaDrm.

This implementation supports pre-acquisition of sessions using preacquireSession.

Summary

Nested types

Builder for DefaultDrmSessionManager instances.

Signals that the drmInitData passed to acquireSession does not contain scheme data for the required UUID.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
public annotation DefaultDrmSessionManager.Mode

Determines the action to be done after a session acquired.

Constants

static final long

Default value for setSessionKeepaliveMs.

static final int

Number of times to retry for initial provisioning and key request for reporting error.

static final int

Downloads an offline license or renews an existing one.

static final int

Loads and refreshes (if necessary) a license for playback.

static final int

Restores an offline license to allow its status to be queried.

static final int

Releases an existing offline license.

static final String
PLAYREADY_CUSTOM_DATA_KEY = "PRCustomData"

A key for specifying PlayReady custom data in the key request parameters passed to setKeyRequestParameters.

Public methods

@Nullable DrmSession
acquireSession(
    @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher,
    Format format
)

Returns a DrmSession for the specified Format, with an incremented reference count.

int

Returns the C.CryptoType that the DRM session manager will use for a given .

DrmSessionManager.DrmSessionReference

Pre-acquires a DRM session for the specified Format.

final void

Acquires any required resources.

final void

Releases any acquired resources.

void
setMode(
    @DefaultDrmSessionManager.Mode int mode,
    @Nullable byte[] offlineLicenseKeySetId
)

Sets the mode, which determines the role of sessions acquired from the instance.

void
setPlayer(Looper playbackLooper, PlayerId playerId)

Sets information about the player using this DRM session manager.

Inherited Constants

From androidx.media3.exoplayer.drm.DrmSessionManager
static final DrmSessionManager

An instance that supports no DRM schemes.

static final DrmSessionManager

This field is deprecated.

Use DRM_UNSUPPORTED.

Constants

DEFAULT_SESSION_KEEPALIVE_MS

public static final long DEFAULT_SESSION_KEEPALIVE_MS = 300000

Default value for setSessionKeepaliveMs.

INITIAL_DRM_REQUEST_RETRY_COUNT

public static final int INITIAL_DRM_REQUEST_RETRY_COUNT = 3

Number of times to retry for initial provisioning and key request for reporting error.

MODE_DOWNLOAD

public static final int MODE_DOWNLOAD = 2

Downloads an offline license or renews an existing one.

MODE_PLAYBACK

public static final int MODE_PLAYBACK = 0

Loads and refreshes (if necessary) a license for playback. Supports streaming and offline licenses.

MODE_QUERY

public static final int MODE_QUERY = 1

Restores an offline license to allow its status to be queried.

MODE_RELEASE

public static final int MODE_RELEASE = 3

Releases an existing offline license.

PLAYREADY_CUSTOM_DATA_KEY

public static final String PLAYREADY_CUSTOM_DATA_KEY = "PRCustomData"

A key for specifying PlayReady custom data in the key request parameters passed to setKeyRequestParameters.

Public methods

acquireSession

public @Nullable DrmSession acquireSession(
    @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher,
    Format format
)

Returns a DrmSession for the specified Format, with an incremented reference count. May return null if the drmInitData is null and the DRM session manager is not configured to attach a DrmSession to clear content. When the caller no longer needs to use a returned DrmSession, it must call release to decrement the reference count.

If the provided Format contains a null drmInitData, the returned 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
@Nullable DrmSessionEventListener.EventDispatcher eventDispatcher

The DrmSessionEventListener.EventDispatcher used to distribute events, and passed on to acquire.

Format format

The Format for which to acquire a DrmSession.

Returns
@Nullable DrmSession

The DRM session. May be null if the given drmInitData is null.

getCryptoType

@C.CryptoType
public int getCryptoType(Format format)

Returns the C.CryptoType that the DRM session manager will use for a given . Returns CRYPTO_TYPE_UNSUPPORTED if the manager does not support any of the DRM schemes defined in the Format. Returns CRYPTO_TYPE_NONE if drmInitData is null and acquireSession will return null for the given Format.

Parameters
Format format

The Format.

Returns
int

The 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. Will be CRYPTO_TYPE_NONE if drmInitData is null and acquireSession will return null for the given Format.

preacquireSession

public DrmSessionManager.DrmSessionReference preacquireSession(
    @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher,
    Format format
)

Pre-acquires a DRM session for the specified Format.

This notifies the manager that a subsequent call to acquireSession with the same Format is likely, allowing a manager that supports pre-acquisition to get the required DrmSession ready in the background.

The caller must call 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 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 re-initializing a new session, including repeating key loads and other async initialization steps.

The caller must separately call acquireSession in order to obtain a session suitable for playback. The pre-acquired DrmSessionReference and full DrmSession instances are distinct. The caller must release both, and can release the DrmSessionReference before the DrmSession without affecting playback.

This can be called from any thread.

Implementations that do not support pre-acquisition always return an empty instance.

Parameters
@Nullable DrmSessionEventListener.EventDispatcher eventDispatcher

The DrmSessionEventListener.EventDispatcher used to distribute events, and passed on to acquire.

Format format

The Format for which to pre-acquire a DrmSession.

Returns
DrmSessionManager.DrmSessionReference

A releaser for the pre-acquired session. Guaranteed to be non-null even if the matching acquireSession would return null.

prepare

public final void prepare()

Acquires any required resources.

release must be called to ensure the acquired resources are released. After releasing, an instance may be re-prepared.

release

public final void release()

Releases any acquired resources.

setMode

public void setMode(
    @DefaultDrmSessionManager.Mode int mode,
    @Nullable byte[] offlineLicenseKeySetId
)

Sets the mode, which determines the role of sessions acquired from the instance. This must be called before acquireSession is called.

By default, the mode is MODE_PLAYBACK and a streaming license is requested when required.

mode must be one of these:

  • MODE_PLAYBACK: If offlineLicenseKeySetId is null then a streaming license is requested. Otherwise, the offline license is restored.
  • MODE_QUERY: offlineLicenseKeySetId cannot be null. The offline license is restored to allow its status to be queried.
  • MODE_DOWNLOAD: If offlineLicenseKeySetId is null then an offline license is requested. Otherwise, the offline license is renewed.
  • MODE_RELEASE: offlineLicenseKeySetId cannot be null. The offline license is released.
Parameters
@DefaultDrmSessionManager.Mode int mode

The mode to be set.

@Nullable byte[] offlineLicenseKeySetId

The key set id of the license to be used with the given mode.

setPlayer

public void setPlayer(Looper playbackLooper, PlayerId playerId)

Sets information about the player using this DRM session manager.

Parameters
Looper playbackLooper

The Looper associated with the player's playback thread.

PlayerId playerId

The PlayerId of the player.