Package com.castlabs.android.drm
Class CastlabsMediaDrm
java.lang.Object
com.castlabs.android.drm.CastlabsMediaDrm
A wrapper around
FrameworkMediaDrm that provides asynchronous session management capabilities.
This class handles DRM session operations with proper resource management and thread safety.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when operations on the MediaDrm instance fail. -
Method Summary
Modifier and TypeMethodDescriptionvoidcloseSession(byte[] sessionId) Asynchronously closes the specified DRM session.voidcloseSessionSync(byte[] sessionId) Synchronously closes the specified DRM session.com.google.android.exoplayer2.drm.FrameworkMediaCryptocreateMediaCrypto(byte[] initData) Creates a MediaCrypto instance for the specified initialization data.com.google.android.exoplayer2.drm.ExoMediaDrm.KeyRequestgetKeyRequest(byte[] scope, List<com.google.android.exoplayer2.drm.DrmInitData.SchemeData> schemeDatas, int keyType, HashMap<String, String> optionalParameters) Gets a key request for the specified session and key type.byte[]getPropertyByteArray(String propertyName) Gets a byte array property from the MediaDrm instance.getPropertyString(String propertyName) Gets a string property from the MediaDrm instance.com.google.android.exoplayer2.drm.ExoMediaDrm.ProvisionRequestGets a provision request for the device.static CastlabsMediaDrmnewInstance(UUID uuid) Creates a new instance of CastlabsMediaDrm for the specified DRM scheme UUID.byte[]Opens a new DRM session.byte[]provideKeyResponse(byte[] scope, byte[] response) Provides a key response for the specified session.voidprovideProvisionResponse(byte[] response) Provides a provision response for the device.queryKeyStatus(byte[] sessionId) Queries the key status for the specified session.voidrelease()Releases all resources associated with this MediaDrm instance.voidAsynchronously releases all resources associated with this MediaDrm instance.voidrestoreKeys(byte[] sessionId, byte[] keySetId) Restores keys for the specified session.voidsetOnEventListener(com.google.android.exoplayer2.drm.ExoMediaDrm.OnEventListener<? super com.google.android.exoplayer2.drm.FrameworkMediaCrypto> listener) Sets the event listener for DRM events.voidsetOnKeyStatusChangeListener(com.google.android.exoplayer2.drm.ExoMediaDrm.OnKeyStatusChangeListener<? super com.google.android.exoplayer2.drm.FrameworkMediaCrypto> listener) Sets the key status change listener for DRM events.voidsetPropertyByteArray(String propertyName, byte[] value) Sets a byte array property on the MediaDrm instance.voidsetPropertyString(String propertyName, String value) Sets a string property on the MediaDrm instance.
-
Method Details
-
newInstance
public static CastlabsMediaDrm newInstance(UUID uuid) throws com.google.android.exoplayer2.drm.UnsupportedDrmException Creates a new instance of CastlabsMediaDrm for the specified DRM scheme UUID.- Parameters:
uuid- The UUID of the DRM scheme to use- Returns:
- A new CastlabsMediaDrm instance
- Throws:
com.google.android.exoplayer2.drm.UnsupportedDrmException- If the DRM scheme is not supported
-
setOnEventListener
public void setOnEventListener(com.google.android.exoplayer2.drm.ExoMediaDrm.OnEventListener<? super com.google.android.exoplayer2.drm.FrameworkMediaCrypto> listener) Sets the event listener for DRM events.- Parameters:
listener- The listener to be notified of DRM events
-
setOnKeyStatusChangeListener
public void setOnKeyStatusChangeListener(com.google.android.exoplayer2.drm.ExoMediaDrm.OnKeyStatusChangeListener<? super com.google.android.exoplayer2.drm.FrameworkMediaCrypto> listener) Sets the key status change listener for DRM events.- Parameters:
listener- The listener to be notified of key status changes
-
openSession
public byte[] openSession() throws NotProvisionedException, ResourceBusyException, MediaDrmExceptionOpens a new DRM session.- Returns:
- The session ID for the newly opened session
- Throws:
NotProvisionedException- If the device is not provisionedResourceBusyException- If the DRM system is busyMediaDrmException- If there was an error opening the session
-
closeSession
public void closeSession(byte[] sessionId) Asynchronously closes the specified DRM session.- Parameters:
sessionId- The ID of the session to close
-
closeSessionSync
public void closeSessionSync(byte[] sessionId) Synchronously closes the specified DRM session.- Parameters:
sessionId- The ID of the session to close
-
getKeyRequest
public com.google.android.exoplayer2.drm.ExoMediaDrm.KeyRequest getKeyRequest(byte[] scope, @Nullable List<com.google.android.exoplayer2.drm.DrmInitData.SchemeData> schemeDatas, int keyType, HashMap<String, String> optionalParameters) throws NotProvisionedExceptionGets a key request for the specified session and key type.- Parameters:
scope- The session IDschemeDatas- The scheme data for the key requestkeyType- The type of key requestoptionalParameters- Optional parameters for the key request- Returns:
- The key request
- Throws:
NotProvisionedException- If the device is not provisioned
-
provideKeyResponse
public byte[] provideKeyResponse(byte[] scope, byte[] response) throws NotProvisionedException, DeniedByServerException Provides a key response for the specified session.- Parameters:
scope- The session IDresponse- The key response- Returns:
- The key response data
- Throws:
NotProvisionedException- If the device is not provisionedDeniedByServerException- If the server denied the request
-
getProvisionRequest
public com.google.android.exoplayer2.drm.ExoMediaDrm.ProvisionRequest getProvisionRequest()Gets a provision request for the device.- Returns:
- The provision request
-
provideProvisionResponse
Provides a provision response for the device.- Parameters:
response- The provision response- Throws:
DeniedByServerException- If the server denied the request
-
queryKeyStatus
Queries the key status for the specified session.- Parameters:
sessionId- The session ID- Returns:
- A map containing the key status information
-
release
public void release()Releases all resources associated with this MediaDrm instance.This method guards against exceptions that may occur during release, particularly on some devices where MediaDrm.release() can throw NullPointerException due to framework issues with service unbinding.
-
releaseAsync
public void releaseAsync()Asynchronously releases all resources associated with this MediaDrm instance. -
restoreKeys
public void restoreKeys(byte[] sessionId, byte[] keySetId) Restores keys for the specified session.- Parameters:
sessionId- The session IDkeySetId- The key set ID to restore
-
getPropertyString
Gets a string property from the MediaDrm instance.- Parameters:
propertyName- The name of the property- Returns:
- The property value
-
getPropertyByteArray
Gets a byte array property from the MediaDrm instance.- Parameters:
propertyName- The name of the property- Returns:
- The property value
-
setPropertyString
Sets a string property on the MediaDrm instance.- Parameters:
propertyName- The name of the propertyvalue- The property value
-
setPropertyByteArray
Sets a byte array property on the MediaDrm instance.- Parameters:
propertyName- The name of the propertyvalue- The property value
-
createMediaCrypto
public com.google.android.exoplayer2.drm.FrameworkMediaCrypto createMediaCrypto(byte[] initData) throws MediaCryptoException Creates a MediaCrypto instance for the specified initialization data.- Parameters:
initData- The initialization data- Returns:
- A new MediaCrypto instance
- Throws:
MediaCryptoException- If there was an error creating the MediaCrypto instance
-