public class DefaultDrmSessionManager<T extends ExoMediaCrypto> extends java.lang.Object implements DrmSessionManager<T>, DrmSession<T>
DrmSessionManager
that supports playbacks using MediaDrm
.Modifier and Type | Class and Description |
---|---|
static interface |
DefaultDrmSessionManager.EventListener
Listener of
DefaultDrmSessionManager events. |
static interface |
DefaultDrmSessionManager.Mode
Determines the action to be done after a session acquired.
|
DrmSession.DrmSessionException, DrmSession.State
Modifier and Type | Field and Description |
---|---|
static int |
MODE_DOWNLOAD
Downloads an offline license or renews an existing one.
|
static int |
MODE_PLAYBACK
Loads and refreshes (if necessary) a license for playback.
|
static int |
MODE_QUERY
Restores an offline license to allow its status to be queried.
|
static int |
MODE_RELEASE
Releases an existing offline license.
|
static java.lang.String |
PLAYREADY_CUSTOM_DATA_KEY
The key to use when passing CustomData to a PlayReady instance in an optional parameter map.
|
STATE_ERROR, STATE_OPENED, STATE_OPENED_WITH_KEYS, STATE_OPENING, STATE_RELEASED
Constructor and Description |
---|
DefaultDrmSessionManager(java.util.UUID uuid,
ExoMediaDrm<T> mediaDrm,
MediaDrmCallback callback,
java.util.HashMap<java.lang.String,java.lang.String> optionalKeyRequestParameters,
android.os.Handler eventHandler,
DefaultDrmSessionManager.EventListener eventListener) |
Modifier and Type | Method and Description |
---|---|
DrmSession<T> |
acquireSession(android.os.Looper playbackLooper,
DrmInitData drmInitData)
Acquires a
DrmSession for the specified DrmInitData . |
boolean |
canAcquireSession(DrmInitData drmInitData)
Returns whether the manager is capable of acquiring a session for the given
DrmInitData . |
DrmSession.DrmSessionException |
getError()
Returns the cause of the error state.
|
T |
getMediaCrypto()
Returns a
ExoMediaCrypto for the open session, or null if called before the session has
been opened or after it's been released. |
byte[] |
getOfflineLicenseKeySetId()
Returns the key set id of the offline license loaded into this session, or null if there isn't
one.
|
byte[] |
getPropertyByteArray(java.lang.String key)
Provides access to
MediaDrm.getPropertyByteArray(String) . |
java.lang.String |
getPropertyString(java.lang.String key)
Provides access to
MediaDrm.getPropertyString(String) . |
int |
getState()
Returns the current state of the session, which is one of
DrmSession.STATE_ERROR ,
DrmSession.STATE_RELEASED , DrmSession.STATE_OPENING , DrmSession.STATE_OPENED and
DrmSession.STATE_OPENED_WITH_KEYS . |
static DefaultDrmSessionManager<FrameworkMediaCrypto> |
newFrameworkInstance(java.util.UUID uuid,
MediaDrmCallback callback,
java.util.HashMap<java.lang.String,java.lang.String> optionalKeyRequestParameters,
android.os.Handler eventHandler,
DefaultDrmSessionManager.EventListener eventListener)
Instantiates a new instance.
|
static DefaultDrmSessionManager<FrameworkMediaCrypto> |
newPlayReadyInstance(MediaDrmCallback callback,
java.lang.String customData,
android.os.Handler eventHandler,
DefaultDrmSessionManager.EventListener eventListener)
Instantiates a new instance using the PlayReady scheme.
|
static DefaultDrmSessionManager<FrameworkMediaCrypto> |
newWidevineInstance(MediaDrmCallback callback,
java.util.HashMap<java.lang.String,java.lang.String> optionalKeyRequestParameters,
android.os.Handler eventHandler,
DefaultDrmSessionManager.EventListener eventListener)
Instantiates a new instance using the Widevine scheme.
|
java.util.Map<java.lang.String,java.lang.String> |
queryKeyStatus()
Returns a map describing the key status for the session, or null if called before the session
has been opened or after it's been released.
|
void |
releaseSession(DrmSession<T> session)
Releases a
DrmSession . |
void |
setMode(int mode,
byte[] offlineLicenseKeySetId)
Sets the mode, which determines the role of sessions acquired from the instance.
|
void |
setPropertyByteArray(java.lang.String key,
byte[] value)
Provides access to
MediaDrm.setPropertyByteArray(String, byte[]) . |
void |
setPropertyString(java.lang.String key,
java.lang.String value)
Provides access to
MediaDrm.setPropertyString(String, String) . |
public static final java.lang.String PLAYREADY_CUSTOM_DATA_KEY
public static final int MODE_PLAYBACK
public static final int MODE_QUERY
DrmSession.STATE_ERROR
.public static final int MODE_DOWNLOAD
public static final int MODE_RELEASE
public DefaultDrmSessionManager(java.util.UUID uuid, ExoMediaDrm<T> mediaDrm, MediaDrmCallback callback, java.util.HashMap<java.lang.String,java.lang.String> optionalKeyRequestParameters, android.os.Handler eventHandler, DefaultDrmSessionManager.EventListener eventListener)
uuid
- The UUID of the drm scheme.mediaDrm
- An underlying ExoMediaDrm
for use by the manager.callback
- Performs key and provisioning requests.optionalKeyRequestParameters
- An optional map of parameters to pass as the last argument
to MediaDrm.getKeyRequest(byte[], byte[], String, int, HashMap)
. May be null.eventHandler
- A handler to use when delivering events to eventListener
. May be
null if delivery of events is not required.eventListener
- A listener of events. May be null if delivery of events is not required.public static DefaultDrmSessionManager<FrameworkMediaCrypto> newWidevineInstance(MediaDrmCallback callback, java.util.HashMap<java.lang.String,java.lang.String> optionalKeyRequestParameters, android.os.Handler eventHandler, DefaultDrmSessionManager.EventListener eventListener) throws UnsupportedDrmException
callback
- Performs key and provisioning requests.optionalKeyRequestParameters
- An optional map of parameters to pass as the last argument
to MediaDrm.getKeyRequest(byte[], byte[], String, int, HashMap)
. May be null.eventHandler
- A handler to use when delivering events to eventListener
. May be
null if delivery of events is not required.eventListener
- A listener of events. May be null if delivery of events is not required.UnsupportedDrmException
- If the specified DRM scheme is not supported.public static DefaultDrmSessionManager<FrameworkMediaCrypto> newPlayReadyInstance(MediaDrmCallback callback, java.lang.String customData, android.os.Handler eventHandler, DefaultDrmSessionManager.EventListener eventListener) throws UnsupportedDrmException
Note that PlayReady is unsupported by most Android devices, with the exception of Android TV devices, which do provide support.
callback
- Performs key and provisioning requests.customData
- Optional custom data to include in requests generated by the instance.eventHandler
- A handler to use when delivering events to eventListener
. May be
null if delivery of events is not required.eventListener
- A listener of events. May be null if delivery of events is not required.UnsupportedDrmException
- If the specified DRM scheme is not supported.public static DefaultDrmSessionManager<FrameworkMediaCrypto> newFrameworkInstance(java.util.UUID uuid, MediaDrmCallback callback, java.util.HashMap<java.lang.String,java.lang.String> optionalKeyRequestParameters, android.os.Handler eventHandler, DefaultDrmSessionManager.EventListener eventListener) throws UnsupportedDrmException
uuid
- The UUID of the drm scheme.callback
- Performs key and provisioning requests.optionalKeyRequestParameters
- An optional map of parameters to pass as the last argument
to MediaDrm.getKeyRequest(byte[], byte[], String, int, HashMap)
. May be null.eventHandler
- A handler to use when delivering events to eventListener
. May be
null if delivery of events is not required.eventListener
- A listener of events. May be null if delivery of events is not required.UnsupportedDrmException
- If the specified DRM scheme is not supported.public final java.lang.String getPropertyString(java.lang.String key)
MediaDrm.getPropertyString(String)
.
This method may be called when the manager is in any state.
key
- The key to request.public final void setPropertyString(java.lang.String key, java.lang.String value)
MediaDrm.setPropertyString(String, String)
.
This method may be called when the manager is in any state.
key
- The property to write.value
- The value to write.public final byte[] getPropertyByteArray(java.lang.String key)
MediaDrm.getPropertyByteArray(String)
.
This method may be called when the manager is in any state.
key
- The key to request.public final void setPropertyByteArray(java.lang.String key, byte[] value)
MediaDrm.setPropertyByteArray(String, byte[])
.
This method may be called when the manager is in any state.
key
- The property to write.value
- The value to write.public void setMode(int mode, byte[] offlineLicenseKeySetId)
acquireSession(Looper, DrmInitData)
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, a streaming license is
requested otherwise the offline license is restored.
MODE_QUERY
: offlineLicenseKeySetId
can not be null. The offline license
is restored.
MODE_DOWNLOAD
: If offlineLicenseKeySetId
is null, an offline license is
requested otherwise the offline license is renewed.
MODE_RELEASE
: offlineLicenseKeySetId
can not be null. The offline license
is released.
mode
- The mode to be set.offlineLicenseKeySetId
- The key set id of the license to be used with the given mode.public boolean canAcquireSession(@NonNull DrmInitData drmInitData)
DrmSessionManager
DrmInitData
.canAcquireSession
in interface DrmSessionManager<T extends ExoMediaCrypto>
drmInitData
- DRM initialization data.DrmInitData
.public DrmSession<T> acquireSession(android.os.Looper playbackLooper, DrmInitData drmInitData)
DrmSessionManager
DrmSession
for the specified DrmInitData
. The DrmSession
must be returned to DrmSessionManager.releaseSession(DrmSession)
when it is no longer required.acquireSession
in interface DrmSessionManager<T extends ExoMediaCrypto>
playbackLooper
- The looper associated with the media playback thread.drmInitData
- DRM initialization data.public void releaseSession(DrmSession<T> session)
DrmSessionManager
DrmSession
.releaseSession
in interface DrmSessionManager<T extends ExoMediaCrypto>
public final int getState()
DrmSession
DrmSession.STATE_ERROR
,
DrmSession.STATE_RELEASED
, DrmSession.STATE_OPENING
, DrmSession.STATE_OPENED
and
DrmSession.STATE_OPENED_WITH_KEYS
.getState
in interface DrmSession<T extends ExoMediaCrypto>
public final DrmSession.DrmSessionException getError()
DrmSession
getError
in interface DrmSession<T extends ExoMediaCrypto>
public final T getMediaCrypto()
DrmSession
ExoMediaCrypto
for the open session, or null if called before the session has
been opened or after it's been released.getMediaCrypto
in interface DrmSession<T extends ExoMediaCrypto>
public java.util.Map<java.lang.String,java.lang.String> queryKeyStatus()
DrmSession
Since DRM license policies vary by vendor, the specific status field names are determined by each DRM vendor. Refer to your DRM provider documentation for definitions of the field names for a particular DRM engine plugin.
queryKeyStatus
in interface DrmSession<T extends ExoMediaCrypto>
MediaDrm.queryKeyStatus(byte[])
public byte[] getOfflineLicenseKeySetId()
DrmSession
getOfflineLicenseKeySetId
in interface DrmSession<T extends ExoMediaCrypto>