MediaFormatUtil
@UnstableApi
class MediaFormatUtil
Helper class containing utility methods for managing MediaFormat instances.
Summary
Constants |
|
|---|---|
const String! |
KEY_MAX_BIT_RATE = "max-bitrate"The |
const String! |
KEY_PCM_ENCODING_EXTENDED = "exo-pcm-encoding-int"Custom |
const String! |
KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT = "exo-pixel-width-height-ratio-float"Custom |
Public functions |
|
|---|---|
java-static Format! |
createFormatFromMediaFormat(mediaFormat: MediaFormat!)Returns a |
java-static MediaFormat! |
createMediaFormatFromFormat(format: Format!)Returns a |
java-static ByteArray<Byte>! |
getArray(byteBuffer: ByteBuffer!) |
java-static ColorInfo? |
getColorInfo(mediaFormat: MediaFormat!)Creates and returns a |
java-static Float |
getFloat(mediaFormat: MediaFormat!, name: String!, defaultValue: Float)Supports |
java-static Float |
getFloatFromIntOrFloat(Returns the value of a key whose value can be set as int or float. |
java-static Int |
getInteger(mediaFormat: MediaFormat!, name: String!, defaultValue: Int)Supports |
java-static String? |
getString(mediaFormat: MediaFormat!, name: String!, defaultValue: String?)Supports |
java-static Int? |
getTimeLapseFrameRate(format: MediaFormat!)Returns the time lapse capture FPS from the given |
java-static Boolean |
isAudioFormat(mediaFormat: MediaFormat!)Returns whether a |
java-static Boolean |
isVideoFormat(mediaFormat: MediaFormat!)Returns whether a |
java-static Unit |
maybeSetByteBuffer(format: MediaFormat!, key: String!, value: ByteArray?)Sets a |
java-static Unit |
maybeSetColorInfo(format: MediaFormat!, colorInfo: ColorInfo?)Sets a |
java-static Unit |
maybeSetFloat(format: MediaFormat!, key: String!, value: Float)Sets a |
java-static Unit |
maybeSetInteger(format: MediaFormat!, key: String!, value: Int)Sets a |
java-static Unit |
maybeSetString(format: MediaFormat!, key: String!, value: String?)Sets a |
java-static Unit |
setCsdBuffers(format: MediaFormat!, csdBuffers: (Mutable)List<ByteArray!>!)Sets a |
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:
getColorInfo
java-static fun getColorInfo(mediaFormat: MediaFormat!): ColorInfo?
Creates and returns a ColorInfo, if a valid instance is described in the MediaFormat.
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.
getFloatFromIntOrFloat
java-static fun getFloatFromIntOrFloat(
mediaFormat: MediaFormat!,
keyName: String!,
defaultValue: Float
): Float
Returns the value of a key whose value can be set as int or float.
The defaultValue is returned if the key is not present in the MediaFormat.
| Throws | |
|---|---|
java.lang.ClassCastException |
If the stored value for the key is other than int or float. |
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 |
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 |
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 |
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 |
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 |
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 |
csdBuffers: (Mutable)List<ByteArray!>! |
The csd buffers to set. |