MediaFormatUtil


@UnstableApi
class MediaFormatUtil


Helper class containing utility methods for managing MediaFormat instances.

Summary

Constants

const String!
KEY_MAX_BIT_RATE = "max-bitrate"

The MediaFormat key for the maximum bitrate in bits per second.

const String!
KEY_PCM_ENCODING_EXTENDED = "exo-pcm-encoding-int"

Custom MediaFormat key associated with an integer representing the PCM encoding.

const String!
KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT = "exo-pixel-width-height-ratio-float"

Custom MediaFormat key associated with a float representing the ratio between a pixel's width and height.

Public functions

java-static Format!

Returns a Format representing the given MediaFormat.

java-static MediaFormat!

Returns a MediaFormat representing the given ExoPlayer Format.

java-static ByteArray<Byte>!
getArray(byteBuffer: ByteBuffer!)
java-static ColorInfo?
getColorInfo(mediaFormat: MediaFormat!)

Creates and returns a ColorInfo, if a valid instance is described in the .

java-static Float
getFloat(mediaFormat: MediaFormat!, name: String!, defaultValue: Float)

Supports getFloat for API < 29.

java-static Int
getInteger(mediaFormat: MediaFormat!, name: String!, defaultValue: Int)

Supports getInteger for API < 29.

java-static String?
getString(mediaFormat: MediaFormat!, name: String!, defaultValue: String?)

Supports getString for API < 29.

java-static Int?

Returns the time lapse capture FPS from the given MediaFormat if it was set.

java-static Boolean
isAudioFormat(mediaFormat: MediaFormat!)

Returns whether a MediaFormat is an audio format.

java-static Boolean
isVideoFormat(mediaFormat: MediaFormat!)

Returns whether a MediaFormat is a video format.

java-static Unit
maybeSetByteBuffer(format: MediaFormat!, key: String!, value: ByteArray?)

Sets a MediaFormatByteBuffer value.

java-static Unit
maybeSetColorInfo(format: MediaFormat!, colorInfo: ColorInfo?)

Sets a MediaFormat's color information.

java-static Unit
maybeSetFloat(format: MediaFormat!, key: String!, value: Float)

Sets a MediaFormat float value.

java-static Unit
maybeSetInteger(format: MediaFormat!, key: String!, value: Int)

Sets a MediaFormat integer value.

java-static Unit
maybeSetString(format: MediaFormat!, key: String!, value: String?)

Sets a MediaFormatString value.

java-static Unit
setCsdBuffers(format: MediaFormat!, csdBuffers: (Mutable)List<ByteArray!>!)

Sets a MediaFormat's codec specific data buffers.

Constants

KEY_MAX_BIT_RATE

const val KEY_MAX_BIT_RATE = "max-bitrate": String!

The MediaFormat key for the maximum bitrate in bits per second.

The associated value is an integer.

The key string constant is the same as MediaFormat#KEY_MAX_BITRATE. Values for it are already returned by the framework MediaExtractor; the key is a hidden field in MediaFormat though, which is why it's being replicated here.

KEY_PCM_ENCODING_EXTENDED

const val KEY_PCM_ENCODING_EXTENDED = "exo-pcm-encoding-int": String!

Custom MediaFormat key associated with an integer representing the PCM encoding.

Equivalent to KEY_PCM_ENCODING, except it allows additional values defined by C.PcmEncoding, including ENCODING_PCM_16BIT_BIG_ENDIAN, ENCODING_PCM_24BIT, ENCODING_PCM_24BIT_BIG_ENDIAN, ENCODING_PCM_32BIT and ENCODING_PCM_32BIT_BIG_ENDIAN.

KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT

const val KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT = "exo-pixel-width-height-ratio-float": String!

Custom MediaFormat key associated with a float representing the ratio between a pixel's width and height.

Public functions

createFormatFromMediaFormat

java-static fun createFormatFromMediaFormat(mediaFormat: MediaFormat!): Format!

Returns a Format representing the given MediaFormat.

createMediaFormatFromFormat

java-static fun createMediaFormatFromFormat(format: Format!): MediaFormat!

Returns a MediaFormat representing the given ExoPlayer Format.

May include the following custom keys:

getArray

java-static fun getArray(byteBuffer: ByteBuffer!): ByteArray<Byte>!

getColorInfo

java-static fun getColorInfo(mediaFormat: MediaFormat!): ColorInfo?

Creates and returns a ColorInfo, if a valid instance is described in the .

Under API 24, null will always be returned, because MediaFormat color keys like KEY_COLOR_STANDARD were only added in API 24.

getFloat

java-static fun getFloat(mediaFormat: MediaFormat!, name: String!, defaultValue: Float): Float

Supports getFloat for API < 29.

getInteger

java-static fun getInteger(mediaFormat: MediaFormat!, name: String!, defaultValue: Int): Int

Supports getInteger for API < 29.

getString

java-static fun getString(mediaFormat: MediaFormat!, name: String!, defaultValue: String?): String?

Supports getString for API < 29.

getTimeLapseFrameRate

java-static fun getTimeLapseFrameRate(format: MediaFormat!): Int?

Returns the time lapse capture FPS from the given MediaFormat if it was set.

isAudioFormat

java-static fun isAudioFormat(mediaFormat: MediaFormat!): Boolean

Returns whether a MediaFormat is an audio format.

isVideoFormat

java-static fun isVideoFormat(mediaFormat: MediaFormat!): Boolean

Returns whether a MediaFormat is a video format.

maybeSetByteBuffer

java-static fun maybeSetByteBuffer(format: MediaFormat!, key: String!, value: ByteArray?): Unit

Sets a MediaFormatByteBuffer value. Does nothing if value is null.

Parameters
format: MediaFormat!

The MediaFormat being configured.

key: String!

The key to set.

value: ByteArray?

The byte array that will be wrapped to obtain the value.

maybeSetColorInfo

java-static fun maybeSetColorInfo(format: MediaFormat!, colorInfo: ColorInfo?): Unit

Sets a MediaFormat's color information. Does nothing if colorInfo is null.

Parameters
format: MediaFormat!

The MediaFormat being configured.

colorInfo: ColorInfo?

The color info to set.

maybeSetFloat

java-static fun maybeSetFloat(format: MediaFormat!, key: String!, value: Float): Unit

Sets a MediaFormat float value. Does nothing if value is NO_VALUE.

Parameters
format: MediaFormat!

The MediaFormat being configured.

key: String!

The key to set.

value: Float

The value to set.

maybeSetInteger

java-static fun maybeSetInteger(format: MediaFormat!, key: String!, value: Int): Unit

Sets a MediaFormat integer value. Does nothing if value is NO_VALUE.

Parameters
format: MediaFormat!

The MediaFormat being configured.

key: String!

The key to set.

value: Int

The value to set.

maybeSetString

java-static fun maybeSetString(format: MediaFormat!, key: String!, value: String?): Unit

Sets a MediaFormatString value. Does nothing if value is null.

Parameters
format: MediaFormat!

The MediaFormat being configured.

key: String!

The key to set.

value: String?

The value to set.

setCsdBuffers

java-static fun setCsdBuffers(format: MediaFormat!, csdBuffers: (Mutable)List<ByteArray!>!): Unit

Sets a MediaFormat's codec specific data buffers.

Parameters
format: MediaFormat!

The MediaFormat being configured.

csdBuffers: (Mutable)List<ByteArray!>!

The csd buffers to set.