DefaultDrmSessionManager


@UnstableApi
class DefaultDrmSessionManager : 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 = )
annotation DefaultDrmSessionManager.Mode

Determines the action to be done after a session acquired.

Constants

const Long

Default value for setSessionKeepaliveMs.

const Int

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

const Int

Downloads an offline license or renews an existing one.

const Int

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

const Int

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

const Int

Releases an existing offline license.

const String!
PLAYREADY_CUSTOM_DATA_KEY = "PRCustomData"

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

Public functions

DrmSession?
acquireSession(
    eventDispatcher: DrmSessionEventListener.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!
preacquireSession(
    eventDispatcher: DrmSessionEventListener.EventDispatcher?,
    format: Format!
)

Pre-acquires a DRM session for the specified Format.

Unit

Acquires any required resources.

Unit

Releases any acquired resources.

Unit
setMode(
    @DefaultDrmSessionManager.Mode mode: Int,
    offlineLicenseKeySetId: ByteArray?
)

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

Unit
setPlayer(playbackLooper: Looper!, playerId: PlayerId!)

Sets information about the player using this DRM session manager.

Inherited Constants

From androidx.media3.exoplayer.drm.DrmSessionManager
const DrmSessionManager!

An instance that supports no DRM schemes.

Constants

DEFAULT_SESSION_KEEPALIVE_MS

const val DEFAULT_SESSION_KEEPALIVE_MS = 300000: Long

Default value for setSessionKeepaliveMs.

INITIAL_DRM_REQUEST_RETRY_COUNT

const val INITIAL_DRM_REQUEST_RETRY_COUNT = 3: Int

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

MODE_DOWNLOAD

const val MODE_DOWNLOAD = 2: Int

Downloads an offline license or renews an existing one.

MODE_PLAYBACK

const val MODE_PLAYBACK = 0: Int

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

MODE_QUERY

const val MODE_QUERY = 1: Int

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

MODE_RELEASE

const val MODE_RELEASE = 3: Int

Releases an existing offline license.

PLAYREADY_CUSTOM_DATA_KEY

const val PLAYREADY_CUSTOM_DATA_KEY = "PRCustomData": String!

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

Public functions

acquireSession

fun acquireSession(
    eventDispatcher: DrmSessionEventListener.EventDispatcher?,
    format: Format!
): DrmSession?

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
eventDispatcher: DrmSessionEventListener.EventDispatcher?

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

format: Format!

The Format for which to acquire a DrmSession.

Returns
DrmSession?

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

getCryptoType

@C.CryptoType
fun getCryptoType(format: Format!): Int

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

fun preacquireSession(
    eventDispatcher: DrmSessionEventListener.EventDispatcher?,
    format: Format!
): DrmSessionManager.DrmSessionReference!

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
eventDispatcher: DrmSessionEventListener.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

fun prepare(): Unit

Acquires any required resources.

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

release

fun release(): Unit

Releases any acquired resources.

setMode

fun setMode(
    @DefaultDrmSessionManager.Mode mode: Int,
    offlineLicenseKeySetId: ByteArray?
): Unit

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 mode: Int

The mode to be set.

offlineLicenseKeySetId: ByteArray?

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

setPlayer

fun setPlayer(playbackLooper: Looper!, playerId: PlayerId!): Unit

Sets information about the player using this DRM session manager.

Parameters
playbackLooper: Looper!

The Looper associated with the player's playback thread.

playerId: PlayerId!

The PlayerId of the player.