Back to Exoplayer

MediaFormatUtil (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/util/MediaFormatUtil.html

latest18.8 KB
Original Source

Package com.google.android.exoplayer2.util

Class MediaFormatUtil


[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public final classMediaFormatUtilextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")

Deprecated. com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.

Helper class containing utility methods for managing MediaFormat instances.

Field Summary

Fields | Modifier and Type | Field | Description | | --- | --- | --- | | static String | KEY_MAX_BIT_RATE | Deprecated.

The MediaFormat key for the maximum bitrate in bits per second. | | static String | KEY_PCM_ENCODING_EXTENDED | Deprecated.

Custom MediaFormat key associated with an integer representing the PCM encoding. | | static String | KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT | Deprecated.

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

Method Summary

All Methods Static Methods Concrete Methods Deprecated Methods | Modifier and Type | Method | Description | | --- | --- | --- | | static Format | createFormatFromMediaFormat​(MediaFormat mediaFormat) | Deprecated.

Returns a Format representing the given MediaFormat. | | static MediaFormat | createMediaFormatFromFormat​(Format format) | Deprecated.

Returns a MediaFormat representing the given ExoPlayer Format. | | static byte[] | getArray​(ByteBuffer byteBuffer) | Deprecated. | | static ColorInfo | getColorInfo​(MediaFormat mediaFormat) | Deprecated.

Creates and returns a ColorInfo, if a valid instance is described in the MediaFormat. | | static float | getFloat​(MediaFormat mediaFormat, String name, float defaultValue) | Deprecated.

Supports MediaFormat.getFloat(String, float) for API < 29. | | static int | getInteger​(MediaFormat mediaFormat, String name, int defaultValue) | Deprecated.

Supports MediaFormat.getInteger(String, int) for API < 29. | | static Integer | getTimeLapseFrameRate​(MediaFormat format) | Deprecated.

Returns the time lapse capture FPS from the given MediaFormat if it was set. | | static boolean | isAudioFormat​(MediaFormat mediaFormat) | Deprecated.

Returns whether a MediaFormat is an audio format. | | static boolean | isVideoFormat​(MediaFormat mediaFormat) | Deprecated.

Returns whether a MediaFormat is a video format. | | static void | maybeSetByteBuffer​(MediaFormat format, String key, byte[] value) | Deprecated.

Sets a MediaFormat ByteBuffer value. | | static void | maybeSetColorInfo​(MediaFormat format, ColorInfo colorInfo) | Deprecated.

Sets a MediaFormat's color information. | | static void | maybeSetFloat​(MediaFormat format, String key, float value) | Deprecated.

Sets a MediaFormat float value. | | static void | maybeSetInteger​(MediaFormat format, String key, int value) | Deprecated.

Sets a MediaFormat integer value. | | static void | maybeSetString​(MediaFormat format, String key, String value) | Deprecated.

Sets a MediaFormat String value. | | static void | setCsdBuffers​(MediaFormat format, List<byte[]> csdBuffers) | Deprecated.

Sets a MediaFormat's codec specific data buffers. |

- 

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

- 

KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT

public static final[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT

Deprecated.

Custom MediaFormat key associated with a float representing the ratio between a pixel's width and height. See Also:Constant Field Values

- 

KEY_PCM_ENCODING_EXTENDED

public static final[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")KEY_PCM_ENCODING_EXTENDED

Deprecated.

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

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

See Also:Constant Field Values

- 

KEY_MAX_BIT_RATE

public static final[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")KEY_MAX_BIT_RATE

Deprecated.

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.

See Also:Constant Field Values

Method Detail

- 

createFormatFromMediaFormat

public static[Format](../Format.html "class in com.google.android.exoplayer2")createFormatFromMediaFormat​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")mediaFormat)

Deprecated.

Returns a Format representing the given MediaFormat.

- 

createMediaFormatFromFormat

public static[MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")createMediaFormatFromFormat​([Format](../Format.html "class in com.google.android.exoplayer2")format)

Deprecated.

Returns a MediaFormat representing the given ExoPlayer Format.

May include the following custom keys:

  - [`KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT`](#KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT). 
  - [`KEY_PCM_ENCODING_EXTENDED`](#KEY_PCM_ENCODING_EXTENDED). 

- 

maybeSetString

public static void maybeSetString​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")format,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")key,
                                  @Nullable[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")value)

Deprecated.

Sets a MediaFormat String value. Does nothing if value is null. Parameters:format - The MediaFormat being configured.key - The key to set.value - The value to set.

- 

setCsdBuffers

public static void setCsdBuffers​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")format,[List](https://developer.android.com/reference/java/util/List.html "class or interface in java.util")<byte[]> csdBuffers)

Deprecated.

Sets a MediaFormat's codec specific data buffers. Parameters:format - The MediaFormat being configured.csdBuffers - The csd buffers to set.

- 

maybeSetInteger

public static void maybeSetInteger​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")format,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")key,
                                   int value)

Deprecated.

Sets a MediaFormat integer value. Does nothing if value is Format.NO_VALUE. Parameters:format - The MediaFormat being configured.key - The key to set.value - The value to set.

- 

maybeSetFloat

public static void maybeSetFloat​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")format,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")key,
                                 float value)

Deprecated.

Sets a MediaFormat float value. Does nothing if value is Format.NO_VALUE. Parameters:format - The MediaFormat being configured.key - The key to set.value - The value to set.

- 

maybeSetByteBuffer

public static void maybeSetByteBuffer​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")format,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")key,
                                      @Nullable
                                      byte[] value)

Deprecated.

Sets a MediaFormat ByteBuffer value. Does nothing if value is null. Parameters:format - The MediaFormat being configured.key - The key to set.value - The byte array that will be wrapped to obtain the value.

- 

maybeSetColorInfo

public static void maybeSetColorInfo​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")format,
                                     @Nullable[ColorInfo](../video/ColorInfo.html "class in com.google.android.exoplayer2.video")colorInfo)

Deprecated.

Sets a MediaFormat's color information. Does nothing if colorInfo is null. Parameters:format - The MediaFormat being configured.colorInfo - The color info to set.

- 

getColorInfo

@Nullable
public static[ColorInfo](../video/ColorInfo.html "class in com.google.android.exoplayer2.video")getColorInfo​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")mediaFormat)

Deprecated.

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 MediaFormat.KEY_COLOR_STANDARD were only added in API 24.

- 

getInteger

public static int getInteger​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")mediaFormat,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")name,
                             int defaultValue)

Deprecated.

Supports MediaFormat.getInteger(String, int) for API < 29.

- 

getFloat

public static float getFloat​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")mediaFormat,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")name,
                             float defaultValue)

Deprecated.

Supports MediaFormat.getFloat(String, float) for API < 29.

- 

getArray

public static byte[] getArray​([ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html "class or interface in java.nio")byteBuffer)

Deprecated.

- 

isVideoFormat

public static boolean isVideoFormat​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")mediaFormat)

Deprecated.

Returns whether a MediaFormat is a video format.

- 

isAudioFormat

public static boolean isAudioFormat​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html "class or interface in android.media")mediaFormat)

Deprecated.

Returns whether a MediaFormat is an audio format.

- 

getTimeLapseFrameRate

@Nullable
public static[Integer](https://developer.android.com/reference/java/lang/Integer.html "class or interface in java.lang")getTimeLapseFrameRate​([MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html?is-external=true "class or interface in android.media")format)

Deprecated.

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