Class MimeTypes
- java.lang.Object
-
- com.google.android.exoplayer2.util.MimeTypes
-
public final class MimeTypes extends Object
Defines common MIME types and helper methods.
-
-
Field Summary
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
allSamplesAreSyncSamples(String mimeType, String codec)
Returns true if it is known that all samples in a stream of the given MIME type and codec are guaranteed to be sync samples (i.e.,C.BUFFER_FLAG_KEY_FRAME
is guaranteed to be set on every sample).static boolean
containsCodecsCorrespondingToMimeType(String codecs, String mimeType)
Returns whether the givencodecs
string contains a codec which corresponds to the givenmimeType
.static String
getAudioMediaMimeType(String codecs)
Returns the first audio MIME type derived from an RFC 6381 codecs string.static String
getCodecsCorrespondingToMimeType(String codecs, String mimeType)
Returns a subsequence ofcodecs
containing the codec strings that correspond to the givenmimeType
.static @com.google.android.exoplayer2.C.Encoding int
getEncoding(String mimeType, String codec)
Returns theC.Encoding
constant corresponding to the specified audio MIME type and RFC 6381 codec string, orC.ENCODING_INVALID
if the correspondingC.Encoding
cannot be determined.static String
getMediaMimeType(String codec)
Returns the MIME type corresponding to an RFC 6381 codec string, ornull
if it could not be determined.static String
getMimeTypeFromMp4ObjectType(int objectType)
Returns the MIME type corresponding to an MP4 object type identifier, as defined in RFC 6381 and https://mp4ra.org/#/object_types.static String
getTextMediaMimeType(String codecs)
Returns the first text MIME type derived from an RFC 6381 codecs string.static @com.google.android.exoplayer2.C.TrackType int
getTrackType(String mimeType)
Returns thetrack type
constant corresponding to a specified MIME type, which may beC.TRACK_TYPE_UNKNOWN
if it could not be determined.static @com.google.android.exoplayer2.C.TrackType int
getTrackTypeOfCodec(String codec)
Equivalent togetTrackType(getMediaMimeType(codec))
.static String
getVideoMediaMimeType(String codecs)
Returns the first video MIME type derived from an RFC 6381 codecs string.static boolean
isAudio(String mimeType)
Returns whether the given string is an audio MIME type.static boolean
isImage(String mimeType)
Returns whether the given string is an image MIME type.static boolean
isMatroska(String mimeType)
Returns whether the givenmimeType
is a Matroska MIME type, including WebM.static boolean
isText(String mimeType)
Returns whether the given string is a text MIME type, including known text types that use "application" as their base type.static boolean
isVideo(String mimeType)
Returns whether the given string is a video MIME type.static String
normalizeMimeType(String mimeType)
Normalizes the MIME type provided so that equivalent MIME types are uniquely represented.static void
registerCustomMimeType(String mimeType, String codecPrefix, @com.google.android.exoplayer2.C.TrackType int trackType)
Registers a custom MIME type.
-
-
-
Field Detail
-
BASE_TYPE_VIDEO
public static final String BASE_TYPE_VIDEO
- See Also:
- Constant Field Values
-
BASE_TYPE_AUDIO
public static final String BASE_TYPE_AUDIO
- See Also:
- Constant Field Values
-
BASE_TYPE_TEXT
public static final String BASE_TYPE_TEXT
- See Also:
- Constant Field Values
-
BASE_TYPE_IMAGE
public static final String BASE_TYPE_IMAGE
- See Also:
- Constant Field Values
-
BASE_TYPE_APPLICATION
public static final String BASE_TYPE_APPLICATION
- See Also:
- Constant Field Values
-
VIDEO_MP4
public static final String VIDEO_MP4
- See Also:
- Constant Field Values
-
VIDEO_MATROSKA
public static final String VIDEO_MATROSKA
- See Also:
- Constant Field Values
-
VIDEO_WEBM
public static final String VIDEO_WEBM
- See Also:
- Constant Field Values
-
VIDEO_H263
public static final String VIDEO_H263
- See Also:
- Constant Field Values
-
VIDEO_H264
public static final String VIDEO_H264
- See Also:
- Constant Field Values
-
VIDEO_H265
public static final String VIDEO_H265
- See Also:
- Constant Field Values
-
VIDEO_VP8
public static final String VIDEO_VP8
- See Also:
- Constant Field Values
-
VIDEO_VP9
public static final String VIDEO_VP9
- See Also:
- Constant Field Values
-
VIDEO_AV1
public static final String VIDEO_AV1
- See Also:
- Constant Field Values
-
VIDEO_MP2T
public static final String VIDEO_MP2T
- See Also:
- Constant Field Values
-
VIDEO_MP4V
public static final String VIDEO_MP4V
- See Also:
- Constant Field Values
-
VIDEO_MPEG
public static final String VIDEO_MPEG
- See Also:
- Constant Field Values
-
VIDEO_PS
public static final String VIDEO_PS
- See Also:
- Constant Field Values
-
VIDEO_MPEG2
public static final String VIDEO_MPEG2
- See Also:
- Constant Field Values
-
VIDEO_VC1
public static final String VIDEO_VC1
- See Also:
- Constant Field Values
-
VIDEO_DIVX
public static final String VIDEO_DIVX
- See Also:
- Constant Field Values
-
VIDEO_FLV
public static final String VIDEO_FLV
- See Also:
- Constant Field Values
-
VIDEO_DOLBY_VISION
public static final String VIDEO_DOLBY_VISION
- See Also:
- Constant Field Values
-
VIDEO_OGG
public static final String VIDEO_OGG
- See Also:
- Constant Field Values
-
VIDEO_AVI
public static final String VIDEO_AVI
- See Also:
- Constant Field Values
-
VIDEO_MJPEG
public static final String VIDEO_MJPEG
- See Also:
- Constant Field Values
-
VIDEO_MP42
public static final String VIDEO_MP42
- See Also:
- Constant Field Values
-
VIDEO_MP43
public static final String VIDEO_MP43
- See Also:
- Constant Field Values
-
VIDEO_UNKNOWN
public static final String VIDEO_UNKNOWN
- See Also:
- Constant Field Values
-
AUDIO_MP4
public static final String AUDIO_MP4
- See Also:
- Constant Field Values
-
AUDIO_AAC
public static final String AUDIO_AAC
- See Also:
- Constant Field Values
-
AUDIO_MATROSKA
public static final String AUDIO_MATROSKA
- See Also:
- Constant Field Values
-
AUDIO_WEBM
public static final String AUDIO_WEBM
- See Also:
- Constant Field Values
-
AUDIO_MPEG
public static final String AUDIO_MPEG
- See Also:
- Constant Field Values
-
AUDIO_MPEG_L1
public static final String AUDIO_MPEG_L1
- See Also:
- Constant Field Values
-
AUDIO_MPEG_L2
public static final String AUDIO_MPEG_L2
- See Also:
- Constant Field Values
-
AUDIO_MPEGH_MHA1
public static final String AUDIO_MPEGH_MHA1
- See Also:
- Constant Field Values
-
AUDIO_MPEGH_MHM1
public static final String AUDIO_MPEGH_MHM1
- See Also:
- Constant Field Values
-
AUDIO_RAW
public static final String AUDIO_RAW
- See Also:
- Constant Field Values
-
AUDIO_ALAW
public static final String AUDIO_ALAW
- See Also:
- Constant Field Values
-
AUDIO_MLAW
public static final String AUDIO_MLAW
- See Also:
- Constant Field Values
-
AUDIO_AC3
public static final String AUDIO_AC3
- See Also:
- Constant Field Values
-
AUDIO_E_AC3
public static final String AUDIO_E_AC3
- See Also:
- Constant Field Values
-
AUDIO_E_AC3_JOC
public static final String AUDIO_E_AC3_JOC
- See Also:
- Constant Field Values
-
AUDIO_AC4
public static final String AUDIO_AC4
- See Also:
- Constant Field Values
-
AUDIO_TRUEHD
public static final String AUDIO_TRUEHD
- See Also:
- Constant Field Values
-
AUDIO_DTS
public static final String AUDIO_DTS
- See Also:
- Constant Field Values
-
AUDIO_DTS_HD
public static final String AUDIO_DTS_HD
- See Also:
- Constant Field Values
-
AUDIO_DTS_EXPRESS
public static final String AUDIO_DTS_EXPRESS
- See Also:
- Constant Field Values
-
AUDIO_DTS_X
public static final String AUDIO_DTS_X
- See Also:
- Constant Field Values
-
AUDIO_VORBIS
public static final String AUDIO_VORBIS
- See Also:
- Constant Field Values
-
AUDIO_OPUS
public static final String AUDIO_OPUS
- See Also:
- Constant Field Values
-
AUDIO_AMR
public static final String AUDIO_AMR
- See Also:
- Constant Field Values
-
AUDIO_AMR_NB
public static final String AUDIO_AMR_NB
- See Also:
- Constant Field Values
-
AUDIO_AMR_WB
public static final String AUDIO_AMR_WB
- See Also:
- Constant Field Values
-
AUDIO_FLAC
public static final String AUDIO_FLAC
- See Also:
- Constant Field Values
-
AUDIO_ALAC
public static final String AUDIO_ALAC
- See Also:
- Constant Field Values
-
AUDIO_MSGSM
public static final String AUDIO_MSGSM
- See Also:
- Constant Field Values
-
AUDIO_OGG
public static final String AUDIO_OGG
- See Also:
- Constant Field Values
-
AUDIO_WAV
public static final String AUDIO_WAV
- See Also:
- Constant Field Values
-
AUDIO_MIDI
public static final String AUDIO_MIDI
- See Also:
- Constant Field Values
-
AUDIO_EXOPLAYER_MIDI
public static final String AUDIO_EXOPLAYER_MIDI
- See Also:
- Constant Field Values
-
AUDIO_UNKNOWN
public static final String AUDIO_UNKNOWN
- See Also:
- Constant Field Values
-
TEXT_VTT
public static final String TEXT_VTT
- See Also:
- Constant Field Values
-
TEXT_SSA
public static final String TEXT_SSA
- See Also:
- Constant Field Values
-
TEXT_EXOPLAYER_CUES
public static final String TEXT_EXOPLAYER_CUES
- See Also:
- Constant Field Values
-
TEXT_UNKNOWN
public static final String TEXT_UNKNOWN
- See Also:
- Constant Field Values
-
APPLICATION_MP4
public static final String APPLICATION_MP4
- See Also:
- Constant Field Values
-
APPLICATION_WEBM
public static final String APPLICATION_WEBM
- See Also:
- Constant Field Values
-
APPLICATION_MATROSKA
public static final String APPLICATION_MATROSKA
- See Also:
- Constant Field Values
-
APPLICATION_MPD
public static final String APPLICATION_MPD
- See Also:
- Constant Field Values
-
APPLICATION_M3U8
public static final String APPLICATION_M3U8
- See Also:
- Constant Field Values
-
APPLICATION_SS
public static final String APPLICATION_SS
- See Also:
- Constant Field Values
-
APPLICATION_ID3
public static final String APPLICATION_ID3
- See Also:
- Constant Field Values
-
APPLICATION_CEA608
public static final String APPLICATION_CEA608
- See Also:
- Constant Field Values
-
APPLICATION_CEA708
public static final String APPLICATION_CEA708
- See Also:
- Constant Field Values
-
APPLICATION_SUBRIP
public static final String APPLICATION_SUBRIP
- See Also:
- Constant Field Values
-
APPLICATION_TTML
public static final String APPLICATION_TTML
- See Also:
- Constant Field Values
-
APPLICATION_TX3G
public static final String APPLICATION_TX3G
- See Also:
- Constant Field Values
-
APPLICATION_MP4VTT
public static final String APPLICATION_MP4VTT
- See Also:
- Constant Field Values
-
APPLICATION_MP4CEA608
public static final String APPLICATION_MP4CEA608
- See Also:
- Constant Field Values
-
APPLICATION_RAWCC
public static final String APPLICATION_RAWCC
- See Also:
- Constant Field Values
-
APPLICATION_VOBSUB
public static final String APPLICATION_VOBSUB
- See Also:
- Constant Field Values
-
APPLICATION_PGS
public static final String APPLICATION_PGS
- See Also:
- Constant Field Values
-
APPLICATION_SCTE35
public static final String APPLICATION_SCTE35
- See Also:
- Constant Field Values
-
APPLICATION_CAMERA_MOTION
public static final String APPLICATION_CAMERA_MOTION
- See Also:
- Constant Field Values
-
APPLICATION_EMSG
public static final String APPLICATION_EMSG
- See Also:
- Constant Field Values
-
APPLICATION_DVBSUBS
public static final String APPLICATION_DVBSUBS
- See Also:
- Constant Field Values
-
APPLICATION_EXIF
public static final String APPLICATION_EXIF
- See Also:
- Constant Field Values
-
APPLICATION_ICY
public static final String APPLICATION_ICY
- See Also:
- Constant Field Values
-
APPLICATION_AIT
public static final String APPLICATION_AIT
- See Also:
- Constant Field Values
-
APPLICATION_RTSP
public static final String APPLICATION_RTSP
- See Also:
- Constant Field Values
-
IMAGE_JPEG
public static final String IMAGE_JPEG
- See Also:
- Constant Field Values
-
CODEC_E_AC3_JOC
public static final String CODEC_E_AC3_JOC
A non-standard codec string for E-AC3-JOC. Use of this constant allows for disambiguation between regular E-AC3 ("ec-3") and E-AC3-JOC ("ec+3") streams from the codec string alone. The standard is to use "ec-3" for both, as per the MP4RA registered codec types.- See Also:
- Constant Field Values
-
-
Method Detail
-
registerCustomMimeType
public static void registerCustomMimeType(String mimeType, String codecPrefix, @com.google.android.exoplayer2.C.TrackType int trackType)
Registers a custom MIME type. Most applications do not need to call this method, as handling of standard MIME types is built in. These built-in MIME types take precedence over any registered via this method. If this method is used, it must be called before creating any player(s).- Parameters:
mimeType
- The custom MIME type to register.codecPrefix
- The RFC 6381 codec string prefix associated with the MIME type.trackType
- Thetrack type
associated with the MIME type. This value is ignored if the top-level type ofmimeType
is audio, video or text.
-
isAudio
public static boolean isAudio(@Nullable String mimeType)
Returns whether the given string is an audio MIME type.
-
isVideo
public static boolean isVideo(@Nullable String mimeType)
Returns whether the given string is a video MIME type.
-
isText
public static boolean isText(@Nullable String mimeType)
Returns whether the given string is a text MIME type, including known text types that use "application" as their base type.
-
isImage
public static boolean isImage(@Nullable String mimeType)
Returns whether the given string is an image MIME type.
-
allSamplesAreSyncSamples
public static boolean allSamplesAreSyncSamples(@Nullable String mimeType, @Nullable String codec)
Returns true if it is known that all samples in a stream of the given MIME type and codec are guaranteed to be sync samples (i.e.,C.BUFFER_FLAG_KEY_FRAME
is guaranteed to be set on every sample).- Parameters:
mimeType
- The MIME type of the stream.codec
- The RFC 6381 codec string of the stream, ornull
if unknown.- Returns:
- Whether it is known that all samples in the stream are guaranteed to be sync samples.
-
getVideoMediaMimeType
@Nullable public static String getVideoMediaMimeType(@Nullable String codecs)
Returns the first video MIME type derived from an RFC 6381 codecs string.- Parameters:
codecs
- An RFC 6381 codecs string.- Returns:
- The first derived video MIME type, or
null
.
-
containsCodecsCorrespondingToMimeType
public static boolean containsCodecsCorrespondingToMimeType(@Nullable String codecs, String mimeType)
Returns whether the givencodecs
string contains a codec which corresponds to the givenmimeType
.- Parameters:
codecs
- An RFC 6381 codecs string.mimeType
- A MIME type to look for.- Returns:
- Whether the given
codecs
string contains a codec which corresponds to the givenmimeType
.
-
getCodecsCorrespondingToMimeType
@Nullable public static String getCodecsCorrespondingToMimeType(@Nullable String codecs, @Nullable String mimeType)
Returns a subsequence ofcodecs
containing the codec strings that correspond to the givenmimeType
. Returns null ifmimeType
is null,codecs
is null, orcodecs
does not contain a codec that corresponds tomimeType
.- Parameters:
codecs
- An RFC 6381 codecs string.mimeType
- A MIME type to look for.- Returns:
- A subsequence of
codecs
containing the codec strings that correspond to the givenmimeType
. Returns null ifmimeType
is null,codecs
is null, orcodecs
does not contain a codec that corresponds tomimeType
.
-
getAudioMediaMimeType
@Nullable public static String getAudioMediaMimeType(@Nullable String codecs)
Returns the first audio MIME type derived from an RFC 6381 codecs string.- Parameters:
codecs
- An RFC 6381 codecs string.- Returns:
- The first derived audio MIME type, or
null
.
-
getTextMediaMimeType
@Nullable public static String getTextMediaMimeType(@Nullable String codecs)
Returns the first text MIME type derived from an RFC 6381 codecs string.- Parameters:
codecs
- An RFC 6381 codecs string.- Returns:
- The first derived text MIME type, or
null
.
-
getMediaMimeType
@Nullable public static String getMediaMimeType(@Nullable String codec)
Returns the MIME type corresponding to an RFC 6381 codec string, ornull
if it could not be determined.- Parameters:
codec
- An RFC 6381 codec string.- Returns:
- The corresponding MIME type, or
null
if it could not be determined.
-
getMimeTypeFromMp4ObjectType
@Nullable public static String getMimeTypeFromMp4ObjectType(int objectType)
Returns the MIME type corresponding to an MP4 object type identifier, as defined in RFC 6381 and https://mp4ra.org/#/object_types.- Parameters:
objectType
- An MP4 object type identifier.- Returns:
- The corresponding MIME type, or
null
if it could not be determined.
-
getTrackType
public static @com.google.android.exoplayer2.C.TrackType int getTrackType(@Nullable String mimeType)
Returns thetrack type
constant corresponding to a specified MIME type, which may beC.TRACK_TYPE_UNKNOWN
if it could not be determined.- Parameters:
mimeType
- A MIME type.- Returns:
- The corresponding
track type
, which may beC.TRACK_TYPE_UNKNOWN
if it could not be determined.
-
getEncoding
public static @com.google.android.exoplayer2.C.Encoding int getEncoding(String mimeType, @Nullable String codec)
Returns theC.Encoding
constant corresponding to the specified audio MIME type and RFC 6381 codec string, orC.ENCODING_INVALID
if the correspondingC.Encoding
cannot be determined.- Parameters:
mimeType
- A MIME type.codec
- An RFC 6381 codec string, ornull
if unknown or not applicable.- Returns:
- The corresponding
C.Encoding
, orC.ENCODING_INVALID
.
-
getTrackTypeOfCodec
public static @com.google.android.exoplayer2.C.TrackType int getTrackTypeOfCodec(String codec)
Equivalent togetTrackType(getMediaMimeType(codec))
.- Parameters:
codec
- An RFC 6381 codec string.- Returns:
- The corresponding
track type
, which may beC.TRACK_TYPE_UNKNOWN
if it could not be determined.
-
normalizeMimeType
public static String normalizeMimeType(String mimeType)
Normalizes the MIME type provided so that equivalent MIME types are uniquely represented.- Parameters:
mimeType
- A MIME type to normalize.- Returns:
- The normalized MIME type, or the argument MIME type if its normalized form is unknown.
-
isMatroska
public static boolean isMatroska(@Nullable String mimeType)
Returns whether the givenmimeType
is a Matroska MIME type, including WebM.
-
-