Added in API level 16

MediaCodecInfo


class MediaCodecInfo
kotlin.Any
   ↳ android.media.MediaCodecInfo

Provides information about a given media codec available on the device. You can iterate through all codecs available by querying MediaCodecList. For example, here's how to find an encoder that supports a given MIME type:

private static MediaCodecInfo selectCodec(String mimeType) {
      int numCodecs = MediaCodecList.getCodecCount();
      for (int i = 0; i < numCodecs; i++) {
          MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
 
          if (!codecInfo.isEncoder()) {
              continue;
          }
 
          String[] types = codecInfo.getSupportedTypes();
          for (int j = 0; j < types.length; j++) {
              if (types[j].equalsIgnoreCase(mimeType)) {
                  return codecInfo;
              }
          }
      }
      return null;
  }

Summary

Nested classes

A class that supports querying the audio capabilities of a codec.

Encapsulates the capabilities of a given codec component.

Encapsulates the profiles available for a codec component.

A class that supports querying the encoding capabilities of a codec.

A class that supports querying the video capabilities of a codec.

Constants
static Int

In this model the codec is not running in a sandboxed process, but written in a memory-safe way.

static Int

In this model the codec is running in a sandboxed process.

Public methods
String

Retrieve the underlying codec name.

MediaCodecInfo.CodecCapabilities!

Enumerates the capabilities of the codec component.

String

Retrieve the codec name.

Int

Query the security model of the codec.

Array<String!>!

Query the media types supported by the codec.

Boolean

Query if the codec is an alias for another underlying codec.

Boolean

Query if the codec is an encoder.

Boolean

Query if the codec is hardware accelerated.

Boolean

Query if the codec is software only.

Boolean

Query if the codec is provided by the Android platform (false) or the device manufacturer (true).

Constants

SECURITY_MODEL_MEMORY_SAFE

static val SECURITY_MODEL_MEMORY_SAFE: Int

In this model the codec is not running in a sandboxed process, but written in a memory-safe way. It typically means that the software implementation of the codec is written in a memory-safe language such as Rust.

Value: 1

SECURITY_MODEL_SANDBOXED

static val SECURITY_MODEL_SANDBOXED: Int

In this model the codec is running in a sandboxed process. Even if a malicious content was fed to the codecs in this model, the impact will be contained in the sandboxed process.

Value: 0

Public methods

getCanonicalName

Added in API level 29
fun getCanonicalName(): String

Retrieve the underlying codec name. Device implementations may provide multiple aliases (codec names) for the same underlying codec to maintain backward app compatibility. This method returns the name of the underlying codec name, which must not be another alias. For non-aliases this is always the name of the codec.

Return
String This value cannot be null.

getCapabilitiesForType

Added in API level 16
fun getCapabilitiesForType(type: String!): MediaCodecInfo.CodecCapabilities!

Enumerates the capabilities of the codec component. Since a single component can support data of a variety of types, the type has to be specified to yield a meaningful result.

Parameters
type String!: The MIME type to query

getName

Added in API level 16
fun getName(): String

Retrieve the codec name. Note: Implementations may provide multiple aliases (codec names) for the same underlying codec, any of which can be used to instantiate the same underlying codec in MediaCodec.createByCodecName. Applications targeting SDK < android.os.Build.VERSION_CODES#Q, cannot determine if the multiple codec names listed in MediaCodecList are in-fact for the same codec.

Return
String This value cannot be null.

getSecurityModel

fun getSecurityModel(): Int

Query the security model of the codec.

Return
Int Value is android.media.MediaCodecInfo#SECURITY_MODEL_SANDBOXED, android.media.MediaCodecInfo#SECURITY_MODEL_MEMORY_SAFE, or android.media.MediaCodecInfo.SECURITY_MODEL_TRUSTED_CONTENT_ONLY

getSupportedTypes

Added in API level 16
fun getSupportedTypes(): Array<String!>!

Query the media types supported by the codec.

isAlias

Added in API level 29
fun isAlias(): Boolean

Query if the codec is an alias for another underlying codec.

isEncoder

Added in API level 16
fun isEncoder(): Boolean

Query if the codec is an encoder.

isHardwareAccelerated

Added in API level 29
fun isHardwareAccelerated(): Boolean

Query if the codec is hardware accelerated. This attribute is provided by the device manufacturer. Note that it cannot be tested for correctness.

isSoftwareOnly

Added in API level 29
fun isSoftwareOnly(): Boolean

Query if the codec is software only. Software-only codecs are more secure as they run in a tighter security sandbox. On the other hand, software-only codecs do not provide any performance guarantees.

isVendor

Added in API level 29
fun isVendor(): Boolean

Query if the codec is provided by the Android platform (false) or the device manufacturer (true).