Stay organized with collections
Save and categorize content based on your preferences.
class MediaCrypto
MediaCrypto class can be used in conjunction with android.media.MediaCodec
to decode encrypted media data. Crypto schemes are assigned 16 byte UUIDs, the method isCryptoSchemeSupported
can be used to query if a given scheme is supported on the device.
Summary
Public constructors |
Instantiate a MediaCrypto object and associate it with a MediaDrm session
|
Public methods |
static Boolean |
Query if the given scheme identified by its UUID is supported on this device.
|
Unit |
|
Boolean |
Query if the crypto scheme requires the use of a secure decoder to decode data of the given mime type.
|
Unit |
Associate a new MediaDrm session with this MediaCrypto instance.
|
Public constructors
MediaCrypto(
uuid: UUID,
sessionId: ByteArray)
Instantiate a MediaCrypto object and associate it with a MediaDrm session
Parameters |
uuid |
UUID: The UUID of the crypto scheme. This value cannot be null . |
sessionId |
ByteArray: The MediaDrm sessionId to associate with this MediaCrypto session. The sessionId may be changed after the MediaCrypto is created using setMediaDrmSession This value cannot be null . |
Public methods
isCryptoSchemeSupported
static fun isCryptoSchemeSupported(uuid: UUID): Boolean
Query if the given scheme identified by its UUID is supported on this device.
Parameters |
uuid |
UUID: The UUID of the crypto scheme. This value cannot be null . |
release
fun release(): Unit
requiresSecureDecoderComponent
fun requiresSecureDecoderComponent(mime: String): Boolean
Query if the crypto scheme requires the use of a secure decoder to decode data of the given mime type.
Parameters |
mime |
String: The mime type of the media data This value cannot be null . |
fun setMediaDrmSession(sessionId: ByteArray): Unit
Associate a new MediaDrm session with this MediaCrypto instance.
The MediaDrm session is used to securely load decryption keys for a crypto scheme. The crypto keys loaded through the MediaDrm session may be selected for use during the decryption operation performed by android.media.MediaCodec#queueSecureInputBuffer
by specifying their key IDs in the android.media.MediaCodec.CryptoInfo#key
field.
Parameters |
sessionId |
ByteArray: The MediaDrm sessionId to associate with this MediaCrypto instance. The session's scheme must match the scheme UUID used when constructing this MediaCrypto instance. This value cannot be null . |
Exceptions |
android.media.MediaCryptoException |
on failure to set the sessionId |
Protected methods
finalize
protected fun finalize(): Unit
Exceptions |
java.lang.Throwable |
the Exception raised by this method |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# MediaCrypto\n\nAdded in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nMediaCrypto\n===========\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/media/MediaCrypto \"View this page in Java\") \n\n```\nclass MediaCrypto\n```\n\n|---|--------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.media.MediaCrypto](#) |\n\nMediaCrypto class can be used in conjunction with [android.media.MediaCodec](/reference/kotlin/android/media/MediaCodec) to decode encrypted media data. Crypto schemes are assigned 16 byte UUIDs, the method [isCryptoSchemeSupported](#isCryptoSchemeSupported(java.util.UUID)) can be used to query if a given scheme is supported on the device.\n\nSummary\n-------\n\n| Public constructors ||\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [MediaCrypto](#MediaCrypto(java.util.UUID,%20kotlin.ByteArray))`(`uuid:` `[UUID](../../java/util/UUID.html#)`, `sessionId:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)`)` Instantiate a MediaCrypto object and associate it with a MediaDrm session |\n\n| Public methods ||\n|-------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [isCryptoSchemeSupported](#isCryptoSchemeSupported(java.util.UUID))`(`uuid:` `[UUID](../../java/util/UUID.html#)`)` Query if the given scheme identified by its UUID is supported on this device. |\n| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [release](#release())`()` \u003cbr /\u003e |\n| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [requiresSecureDecoderComponent](#requiresSecureDecoderComponent(kotlin.String))`(`mime:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` Query if the crypto scheme requires the use of a secure decoder to decode data of the given mime type. |\n| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [setMediaDrmSession](#setMediaDrmSession(kotlin.ByteArray))`(`sessionId:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)`)` Associate a new MediaDrm session with this MediaCrypto instance. |\n\n| Protected methods ||\n|------------------------------------------------------------------------------|------------------------------------|\n| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [finalize](#finalize())`()` \u003cbr /\u003e |\n\nPublic constructors\n-------------------\n\n### MediaCrypto\n\nAdded in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nMediaCrypto(\n uuid: UUID, \n sessionId: ByteArray)\n```\n\nInstantiate a MediaCrypto object and associate it with a MediaDrm session\n\n| Parameters ||\n|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `uuid` | [UUID](../../java/util/UUID.html#): The UUID of the crypto scheme. This value cannot be `null`. |\n| `sessionId` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html): The MediaDrm sessionId to associate with this MediaCrypto session. The sessionId may be changed after the MediaCrypto is created using [setMediaDrmSession](#setMediaDrmSession(kotlin.ByteArray)) This value cannot be `null`. |\n\nPublic methods\n--------------\n\n### isCryptoSchemeSupported\n\nAdded in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nstatic fun isCryptoSchemeSupported(uuid: UUID): Boolean\n```\n\nQuery if the given scheme identified by its UUID is supported on this device.\n\n| Parameters ||\n|--------|-------------------------------------------------------------------------------------------------|\n| `uuid` | [UUID](../../java/util/UUID.html#): The UUID of the crypto scheme. This value cannot be `null`. |\n\n### release\n\nAdded in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun release(): Unit\n``` \n\n### requiresSecureDecoderComponent\n\nAdded in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun requiresSecureDecoderComponent(mime: String): Boolean\n```\n\nQuery if the crypto scheme requires the use of a secure decoder to decode data of the given mime type.\n\n| Parameters ||\n|--------|------------------------------------------------------------------------------------------------------------------------------------------------|\n| `mime` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html): The mime type of the media data This value cannot be `null`. |\n\n### setMediaDrmSession\n\nAdded in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun setMediaDrmSession(sessionId: ByteArray): Unit\n```\n\nAssociate a new MediaDrm session with this MediaCrypto instance.\n\nThe MediaDrm session is used to securely load decryption keys for a crypto scheme. The crypto keys loaded through the MediaDrm session may be selected for use during the decryption operation performed by [android.media.MediaCodec#queueSecureInputBuffer](/reference/kotlin/android/media/MediaCodec#queueSecureInputBuffer(kotlin.Int,%20kotlin.Int,%20android.media.MediaCodec.CryptoInfo,%20kotlin.Long,%20kotlin.Int)) by specifying their key IDs in the [android.media.MediaCodec.CryptoInfo#key](/reference/kotlin/android/media/MediaCodec.CryptoInfo#key:kotlin.ByteArray) field.\n\n| Parameters ||\n|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `sessionId` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html): The MediaDrm sessionId to associate with this MediaCrypto instance. The session's scheme must match the scheme UUID used when constructing this MediaCrypto instance. This value cannot be `null`. |\n\n| Exceptions ||\n|--------------------------------------|---------------------------------|\n| `android.media.MediaCryptoException` | on failure to set the sessionId |\n\nProtected methods\n-----------------\n\n### finalize\n\nAdded in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nprotected fun finalize(): Unit\n```\n\n| Exceptions ||\n|-----------------------|---------------------------------------|\n| `java.lang.Throwable` | the `Exception` raised by this method |"]]