# MediaCodec.CryptoException

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# CryptoException

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/media/MediaCodec.CryptoException "View this page in Java")  

```
class CryptoException : RuntimeException, MediaDrmThrowable
```

|---|---|---|---|--------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                |||||
| ↳ | [kotlin.Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)                                                 ||||
|   | ↳ | [java.lang.Exception](https://developer.android.com/reference/kotlin/java/lang/Exception.html#)                                            |||
|   |   | ↳ | [java.lang.RuntimeException](https://developer.android.com/reference/kotlin/java/lang/RuntimeException.html#)                           ||
|   |   |   | ↳ | [android.media.MediaCodec.CryptoException](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#) |

Thrown when a crypto error occurs while queueing a secure input buffer.

## Summary

|                                                                                                                                                                                                                               Constants                                                                                                                                                                                                                               ||
|----------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ERROR_FRAME_TOO_LARGE](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#ERROR_FRAME_TOO_LARGE:kotlin.Int) This indicates that the video frame being decrypted exceeds the size of the device's protected output buffers.                                                                                                                    |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ERROR_INSUFFICIENT_OUTPUT_PROTECTION](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#ERROR_INSUFFICIENT_OUTPUT_PROTECTION:kotlin.Int) This indicates that the output protection levels supported by the device are not sufficient to meet the requirements set by the content owner in the license policy.                                |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ERROR_INSUFFICIENT_SECURITY](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#ERROR_INSUFFICIENT_SECURITY:kotlin.Int) This indicates that the security level of the device is not sufficient to meet the requirements set by the content owner in the license policy.                                                                       |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ERROR_KEY_EXPIRED](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#ERROR_KEY_EXPIRED:kotlin.Int) This indicates that the key used for decryption is no longer valid due to license term expiration.                                                                                                                                        |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ERROR_LOST_STATE](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#ERROR_LOST_STATE:kotlin.Int) This error indicates that session state has been invalidated.                                                                                                                                                                               |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ERROR_NO_KEY](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#ERROR_NO_KEY:kotlin.Int) This indicates that the requested key was not found when trying to perform a decrypt operation.                                                                                                                                                     |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ERROR_RESOURCE_BUSY](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#ERROR_RESOURCE_BUSY:kotlin.Int) This indicates that a required crypto resource was not able to be allocated while attempting the requested operation.                                                                                                                 |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ERROR_SESSION_NOT_OPENED](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#ERROR_SESSION_NOT_OPENED:kotlin.Int) This indicates that decryption was attempted on a session that is not opened, which could be due to a failure to open the session, closing the session prematurely, or the session being reclaimed by the resource manager. |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ERROR_UNSUPPORTED_OPERATION](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#ERROR_UNSUPPORTED_OPERATION:kotlin.Int) This indicates that an operation was attempted that could not be supported by the crypto system of the device in its current configuration.                                                                           |

|                                                                                                                                                                         Public constructors                                                                                                                                                                          ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [CryptoException](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#CryptoException(kotlin.Int,%20kotlin.String))`(`errorCode:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `detailMessage:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?`)` <br /> |

|                                                                                                                                                                                           Public methods                                                                                                                                                                                            ||
|--------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [MediaCodec.CryptoInfo](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoInfo)? | [getCryptoInfo](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#getCryptoInfo())`()` Returns CryptoInfo associated with this[CryptoException](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#)if any |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                                   | [getErrorCode](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#getErrorCode())`()` Returns error code associated with this[CryptoException](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#).        |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                                   | [getErrorContext](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#getErrorContext())`()` <br />                                                                                                                                               |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                                   | [getOemError](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#getOemError())`()` <br />                                                                                                                                                       |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                                   | [getVendorError](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#getVendorError())`()` <br />                                                                                                                                                 |

## Constants

### ERROR_FRAME_TOO_LARGE

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val ERROR_FRAME_TOO_LARGE: Int
```

**Deprecated:** *Please use[MediaDrm.ErrorCodes.ERROR_FRAME_TOO_LARGE](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_FRAME_TOO_LARGE:kotlin.Int)*

This indicates that the video frame being decrypted exceeds the size of the device's protected output buffers. When encountering this error the app should try playing content of a lower resolution.  

    Value: 8

### ERROR_INSUFFICIENT_OUTPUT_PROTECTION

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val ERROR_INSUFFICIENT_OUTPUT_PROTECTION: Int
```

**Deprecated:** *Please use[MediaDrm.ErrorCodes.ERROR_INSUFFICIENT_OUTPUT_PROTECTION](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_INSUFFICIENT_OUTPUT_PROTECTION:kotlin.Int)*

This indicates that the output protection levels supported by the device are not sufficient to meet the requirements set by the content owner in the license policy.  

    Value: 4

### ERROR_INSUFFICIENT_SECURITY

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val ERROR_INSUFFICIENT_SECURITY: Int
```

**Deprecated:** *Please use[MediaDrm.ErrorCodes.ERROR_INSUFFICIENT_SECURITY](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_INSUFFICIENT_SECURITY:kotlin.Int)*

This indicates that the security level of the device is not sufficient to meet the requirements set by the content owner in the license policy.  

    Value: 7

### ERROR_KEY_EXPIRED

Added in[API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val ERROR_KEY_EXPIRED: Int
```

**Deprecated:** *Please use[MediaDrm.ErrorCodes.ERROR_KEY_EXPIRED](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_KEY_EXPIRED:kotlin.Int).*

This indicates that the key used for decryption is no longer valid due to license term expiration. The operation can be retried after updating the expired keys.  

    Value: 2

### ERROR_LOST_STATE

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val ERROR_LOST_STATE: Int
```

**Deprecated:** *Please use[MediaDrm.ErrorCodes.ERROR_LOST_STATE](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_LOST_STATE:kotlin.Int)*

This error indicates that session state has been invalidated. It can occur on devices that are not capable of retaining crypto session state across device suspend/resume. The session must be closed and a new session opened to resume operation.  

    Value: 9

### ERROR_NO_KEY

Added in[API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val ERROR_NO_KEY: Int
```

**Deprecated:** *Please use[MediaDrm.ErrorCodes.ERROR_NO_KEY](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_NO_KEY:kotlin.Int).*

This indicates that the requested key was not found when trying to perform a decrypt operation. The operation can be retried after adding the correct decryption key.  

    Value: 1

### ERROR_RESOURCE_BUSY

Added in[API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val ERROR_RESOURCE_BUSY: Int
```

**Deprecated:** *Please use[MediaDrm.ErrorCodes.ERROR_RESOURCE_BUSY](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_RESOURCE_BUSY:kotlin.Int)*

This indicates that a required crypto resource was not able to be allocated while attempting the requested operation. The operation can be retried if the app is able to release resources.  

    Value: 3

### ERROR_SESSION_NOT_OPENED

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val ERROR_SESSION_NOT_OPENED: Int
```

**Deprecated:** *Please use[MediaDrm.ErrorCodes.ERROR_SESSION_NOT_OPENED](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_SESSION_NOT_OPENED:kotlin.Int)*

This indicates that decryption was attempted on a session that is not opened, which could be due to a failure to open the session, closing the session prematurely, or the session being reclaimed by the resource manager.  

    Value: 5

### ERROR_UNSUPPORTED_OPERATION

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val ERROR_UNSUPPORTED_OPERATION: Int
```

**Deprecated:** *Please use[MediaDrm.ErrorCodes.ERROR_UNSUPPORTED_OPERATION](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_UNSUPPORTED_OPERATION:kotlin.Int)*

This indicates that an operation was attempted that could not be supported by the crypto system of the device in its current configuration. It may occur when the license policy requires device security features that aren't supported by the device, or due to an internal error in the crypto system that prevents the specified security policy from being met.  

    Value: 6

## Public constructors

### CryptoException

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
CryptoException(
    errorCode: Int, 
    detailMessage: String?)
```

|                                                         Parameters                                                          ||
|-----------------|------------------------------------------------------------------------------------------------------------|
| `detailMessage` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?:This value may be`null`. |

## Public methods

### getCryptoInfo

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getCryptoInfo(): MediaCodec.CryptoInfo?
```

Returns CryptoInfo associated with this[CryptoException](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#)if any

|                                                                                                                                        Return                                                                                                                                         ||
|--------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [MediaCodec.CryptoInfo](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoInfo)? | CryptoInfo object if any.[MediaCodec.CryptoException](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#)This value may be`null`. |

### getErrorCode

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getErrorCode(): Int
```

Returns error code associated with this[CryptoException](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoException#).

Please refer to[MediaDrm.ErrorCodes](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes)for the general error handling strategy and details about each possible return value.

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       Return                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ||
|----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | an error code defined in[MediaDrm.ErrorCodes](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes). Value is[android.media.MediaDrm.ErrorCodes#ERROR_NO_KEY](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_NO_KEY:kotlin.Int),[android.media.MediaDrm.ErrorCodes#ERROR_KEY_EXPIRED](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_KEY_EXPIRED:kotlin.Int),[android.media.MediaDrm.ErrorCodes#ERROR_RESOURCE_BUSY](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_RESOURCE_BUSY:kotlin.Int),[android.media.MediaDrm.ErrorCodes#ERROR_INSUFFICIENT_OUTPUT_PROTECTION](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_INSUFFICIENT_OUTPUT_PROTECTION:kotlin.Int),[android.media.MediaDrm.ErrorCodes#ERROR_SESSION_NOT_OPENED](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_SESSION_NOT_OPENED:kotlin.Int),[android.media.MediaDrm.ErrorCodes#ERROR_UNSUPPORTED_OPERATION](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_UNSUPPORTED_OPERATION:kotlin.Int),[android.media.MediaDrm.ErrorCodes#ERROR_INSUFFICIENT_SECURITY](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_INSUFFICIENT_SECURITY:kotlin.Int),[android.media.MediaDrm.ErrorCodes#ERROR_FRAME_TOO_LARGE](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_FRAME_TOO_LARGE:kotlin.Int),[android.media.MediaDrm.ErrorCodes#ERROR_LOST_STATE](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_LOST_STATE:kotlin.Int),[android.media.MediaDrm.ErrorCodes#ERROR_GENERIC_OEM](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_GENERIC_OEM:kotlin.Int),[android.media.MediaDrm.ErrorCodes#ERROR_GENERIC_PLUGIN](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_GENERIC_PLUGIN:kotlin.Int),[android.media.MediaDrm.ErrorCodes#ERROR_LICENSE_PARSE](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_LICENSE_PARSE:kotlin.Int),[android.media.MediaDrm.ErrorCodes#ERROR_MEDIA_FRAMEWORK](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_MEDIA_FRAMEWORK:kotlin.Int), or[android.media.MediaDrm.ErrorCodes#ERROR_ZERO_SUBSAMPLES](https://developer.android.com/reference/kotlin/android/media/MediaDrm.ErrorCodes#ERROR_ZERO_SUBSAMPLES:kotlin.Int) |

### getErrorContext

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getErrorContext(): Int
```

|                                                                                                                                Return                                                                                                                                ||
|----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | an opaque integer that would help the @[MediaDrm](https://developer.android.com/reference/kotlin/android/media/MediaDrm)vendor locate the source of the error if available, otherwise 0. |

### getOemError

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getOemError(): Int
```

|                                                                  Return                                                                  ||
|----------------------------------------------------------------------------|--------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | an OEM or SOC specific error code if available, otherwise 0. |

### getVendorError

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getVendorError(): Int
```

|                                                                                                              Return                                                                                                               ||
|----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | an error code defined by the[MediaDrm](https://developer.android.com/reference/kotlin/android/media/MediaDrm)plugin vendor if available, otherwise 0. |