/**@class android.media.MediaExtractor @extends java.lang.Object MediaExtractor facilitates extraction of demuxed, typically encoded, media data from a data source. <p>It is generally used like this: <pre> MediaExtractor extractor = new MediaExtractor(); extractor.setDataSource(...); int numTracks = extractor.getTrackCount(); for (int i = 0; i < numTracks; ++i) { MediaFormat format = extractor.getTrackFormat(i); String mime = format.getString(MediaFormat.KEY_MIME); if (weAreInterestedInThisTrack) { extractor.selectTrack(i); } } ByteBuffer inputBuffer = ByteBuffer.allocate(...) while (extractor.readSampleData(inputBuffer, ...) >= 0) { int trackIndex = extractor.getSampleTrackIndex(); long presentationTimeUs = extractor.getSampleTime(); ... extractor.advance(); } extractor.release(); extractor = null; </pre> <p>This class requires the {@link android.Manifest.permission#INTERNET} permission when used with network-based content. */ var MediaExtractor = { /** If possible, seek to a sync sample at or before the specified time */ SEEK_TO_PREVIOUS_SYNC : "0", /** If possible, seek to a sync sample at or after the specified time */ SEEK_TO_NEXT_SYNC : "1", /** If possible, seek to the sync sample closest to the specified time */ SEEK_TO_CLOSEST_SYNC : "2", /** The sample is a sync sample (or in {@link android.media.MediaCodec}'s terminology it is a key frame.) @see MediaCodec#BUFFER_FLAG_KEY_FRAME */ SAMPLE_FLAG_SYNC : "1", /** The sample is (at least partially) encrypted, see also the documentation for {@link android.media.MediaCodec#queueSecureInputBuffer} */ SAMPLE_FLAG_ENCRYPTED : "2", /** This indicates that the buffer only contains part of a frame, and the decoder should batch the data until a buffer without this flag appears before decoding the frame. @see MediaCodec#BUFFER_FLAG_PARTIAL_FRAME */ SAMPLE_FLAG_PARTIAL_FRAME : "4", /**Sets the data source (MediaDataSource) to use. @param {Object {MediaDataSource}} dataSource the MediaDataSource for the media you want to extract from @throws IllegalArgumentException if dataSource is invalid. */ setDataSource : function( ) {}, /**Sets the data source as a content Uri. @param {Object {Context}} context the Context to use when resolving the Uri @param {Object {Uri}} uri the Content URI of the data you want to extract from. <p>When <code>uri</code> refers to a network file the {@link android.Manifest.permission#INTERNET} permission is required. @param {Object {java.util.Map}} headers the headers to be sent together with the request for the data. This can be {@code null} if no specific headers are to be sent with the request. */ setDataSource : function( ) {}, /**Sets the data source (file-path or http URL) to use. @param {String} path the path of the file, or the http URL <p>When <code>path</code> refers to a network file the {@link android.Manifest.permission#INTERNET} permission is required. @param {Object {java.util.Map}} headers the headers associated with the http request for the stream you want to play. This can be {@code null} if no specific headers are to be sent with the request. */ setDataSource : function( ) {}, /**Sets the data source (file-path or http URL) to use. @param {String} path the path of the file, or the http URL of the stream <p>When <code>path</code> refers to a local file, the file may actually be opened by a process other than the calling application. This implies that the pathname should be an absolute path (as any other process runs with unspecified current working directory), and that the pathname should reference a world-readable file. As an alternative, the application could first open the file for reading, and then use the file descriptor form {@link #setDataSource(FileDescriptor)}. <p>When <code>path</code> refers to a network file the {@link android.Manifest.permission#INTERNET} permission is required. */ setDataSource : function( ) {}, /**Sets the data source (AssetFileDescriptor) to use. It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns. @param {Object {AssetFileDescriptor}} afd the AssetFileDescriptor for the file you want to extract from. */ setDataSource : function( ) {}, /**Sets the data source (FileDescriptor) to use. It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns. @param {Object {FileDescriptor}} fd the FileDescriptor for the file you want to extract from. */ setDataSource : function( ) {}, /**Sets the data source (FileDescriptor) to use. The FileDescriptor must be seekable (N.B. a LocalSocket is not seekable). It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns. @param {Object {FileDescriptor}} fd the FileDescriptor for the file you want to extract from. @param {Number} offset the offset into the file where the data to be extracted starts, in bytes @param {Number} length the length in bytes of the data to be extracted */ setDataSource : function( ) {}, /**Sets the MediaCas instance to use. This should be called after a successful setDataSource() if at least one track reports mime type of {@link android.media.MediaFormat#MIMETYPE_AUDIO_SCRAMBLED} or {@link android.media.MediaFormat#MIMETYPE_VIDEO_SCRAMBLED}. Stream parsing will not proceed until a valid MediaCas object is provided. @param {Object {MediaCas}} mediaCas the MediaCas object to use. */ setMediaCas : function( ) {}, /**Retrieves the information about the conditional access system used to scramble a track. @param {Number} index of the track. @return {Object {android.media.MediaExtractor.CasInfo}} an {@link CasInfo} object describing the conditional access system. */ getCasInfo : function( ) {}, /**Make sure you call this when you're done to free up any resources instead of relying on the garbage collector to do this for you at some point in the future. */ release : function( ) {}, /**Count the number of tracks found in the data source. */ getTrackCount : function( ) {}, /**Extract DRM initialization data if it exists @return {Object {android.media.DrmInitData}} DRM initialization data in the content, or {@code null} if no recognizable DRM format is found; @see DrmInitData */ getDrmInitData : function( ) {}, /**Get the list of available audio presentations for the track. @param {Number} trackIndex index of the track. @return {Object {java.util.List}} a list of available audio presentations for a given valid audio track index. The list will be empty if the source does not contain any audio presentations. */ getAudioPresentations : function( ) {}, /**Get the PSSH info if present. @return {Object {java.util.Map}} a map of uuid-to-bytes, with the uuid specifying the crypto scheme, and the bytes being the data specific to that scheme. This can be {@code null} if the source does not contain PSSH info. */ getPsshInfo : function( ) {}, /**Get the track format at the specified index. More detail on the representation can be found at {@link android.media.MediaCodec} <p> The following table summarizes support for format keys across android releases: <table style="width: 0%"> <thead> <tr> <th rowspan=2>OS Version(s)</th> <td colspan=3>{@code MediaFormat} keys used for</th> </tr><tr> <th>All Tracks</th> <th>Audio Tracks</th> <th>Video Tracks</th> </tr> </thead> <tbody> <tr> <td>{@link android.os.Build.VERSION_CODES#JELLY_BEAN}</td> <td rowspan=8>{@link android.media.MediaFormat#KEY_MIME},<br> {@link android.media.MediaFormat#KEY_DURATION},<br> {@link android.media.MediaFormat#KEY_MAX_INPUT_SIZE}</td> <td rowspan=5>{@link android.media.MediaFormat#KEY_SAMPLE_RATE},<br> {@link android.media.MediaFormat#KEY_CHANNEL_COUNT},<br> {@link android.media.MediaFormat#KEY_CHANNEL_MASK},<br> gapless playback information<sup>.mp3, .mp4</sup>,<br> {@link android.media.MediaFormat#KEY_IS_ADTS}<sup>AAC if streaming</sup>,<br> codec-specific data<sup>AAC, Vorbis</sup></td> <td rowspan=2>{@link android.media.MediaFormat#KEY_WIDTH},<br> {@link android.media.MediaFormat#KEY_HEIGHT},<br> codec-specific data<sup>AVC, MPEG4</sup></td> </tr><tr> <td>{@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}</td> </tr><tr> <td>{@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}</td> <td rowspan=3>as above, plus<br> Pixel aspect ratio information<sup>AVC, *</sup></td> </tr><tr> <td>{@link android.os.Build.VERSION_CODES#KITKAT}</td> </tr><tr> <td>{@link android.os.Build.VERSION_CODES#KITKAT_WATCH}</td> </tr><tr> <td>{@link android.os.Build.VERSION_CODES#LOLLIPOP}</td> <td rowspan=2>as above, plus<br> {@link android.media.MediaFormat#KEY_BIT_RATE}<sup>AAC</sup>,<br> codec-specific data<sup>Opus</sup></td> <td rowspan=2>as above, plus<br> {@link android.media.MediaFormat#KEY_ROTATION}<sup>.mp4</sup>,<br> {@link android.media.MediaFormat#KEY_BIT_RATE}<sup>MPEG4</sup>,<br> codec-specific data<sup>HEVC</sup></td> </tr><tr> <td>{@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}</td> </tr><tr> <td>{@link android.os.Build.VERSION_CODES#M}</td> <td>as above, plus<br> gapless playback information<sup>Opus</sup></td> <td>as above, plus<br> {@link android.media.MediaFormat#KEY_FRAME_RATE} (integer)</td> </tr><tr> <td>{@link android.os.Build.VERSION_CODES#N}</td> <td>as above, plus<br> {@link android.media.MediaFormat#KEY_TRACK_ID},<br> <!-- {link MediaFormat#KEY_MAX_BIT_RATE}<sup>#, .mp4</sup>,<br> --> {@link android.media.MediaFormat#KEY_BIT_RATE}<sup>#, .mp4</sup></td> <td>as above, plus<br> {@link android.media.MediaFormat#KEY_PCM_ENCODING},<br> {@link android.media.MediaFormat#KEY_PROFILE}<sup>AAC</sup></td> <td>as above, plus<br> {@link android.media.MediaFormat#KEY_HDR_STATIC_INFO}<sup>#, .webm</sup>,<br> {@link android.media.MediaFormat#KEY_COLOR_STANDARD}<sup>#</sup>,<br> {@link android.media.MediaFormat#KEY_COLOR_TRANSFER}<sup>#</sup>,<br> {@link android.media.MediaFormat#KEY_COLOR_RANGE}<sup>#</sup>,<br> {@link android.media.MediaFormat#KEY_PROFILE}<sup>MPEG2, H.263, MPEG4, AVC, HEVC, VP9</sup>,<br> {@link android.media.MediaFormat#KEY_LEVEL}<sup>H.263, MPEG4, AVC, HEVC, VP9</sup>,<br> codec-specific data<sup>VP9</sup></td> </tr> <tr> <td colspan=4> <p class=note><strong>Notes:</strong><br> #: container-specified value only.<br> .mp4, .webm…: for listed containers<br> MPEG4, AAC…: for listed codecs </td> </tr><tr> <td colspan=4> <p class=note>Note that that level information contained in the container many times does not match the level of the actual bitstream. You may want to clear the level using {@code MediaFormat.setString(KEY_LEVEL, null)} before using the track format to find a decoder that can play back a particular track. </td> </tr><tr> <td colspan=4> <p class=note><strong>*Pixel (sample) aspect ratio</strong> is returned in the following keys. The display width can be calculated for example as: <p align=center> display-width = display-height * crop-width / crop-height * sar-width / sar-height </td> </tr><tr> <th>Format Key</th><th>Value Type</th><th colspan=2>Description</th> </tr><tr> <td>{@code "sar-width"}</td><td>Integer</td><td colspan=2>Pixel aspect ratio width</td> </tr><tr> <td>{@code "sar-height"}</td><td>Integer</td><td colspan=2>Pixel aspect ratio height</td> </tr> </tbody> </table> */ getTrackFormat : function( ) {}, /**Subsequent calls to {@link #readSampleData}, {@link #getSampleTrackIndex} and {@link #getSampleTime} only retrieve information for the subset of tracks selected. Selecting the same track multiple times has no effect, the track is only selected once. */ selectTrack : function( ) {}, /**Subsequent calls to {@link #readSampleData}, {@link #getSampleTrackIndex} and {@link #getSampleTime} only retrieve information for the subset of tracks selected. */ unselectTrack : function( ) {}, /**All selected tracks seek near the requested time according to the specified mode. */ seekTo : function( ) {}, /**Advance to the next sample. Returns false if no more sample data is available (end of stream). When extracting a local file, the behaviors of {@link #advance} and {@link #readSampleData} are undefined in presence of concurrent writes to the same local file; more specifically, end of stream could be signalled earlier than expected. */ advance : function( ) {}, /**Retrieve the current encoded sample and store it in the byte buffer starting at the given offset. <p> <b>Note:</b>As of API 21, on success the position and limit of {@code byteBuf} is updated to point to the data just read. @param {Object {ByteBuffer}} byteBuf the destination byte buffer @return {Number} the sample size (or -1 if no more samples are available). */ readSampleData : function( ) {}, /**Returns the track index the current sample originates from (or -1 if no more samples are available) */ getSampleTrackIndex : function( ) {}, /**Returns the current sample's presentation time in microseconds. or -1 if no more samples are available. */ getSampleTime : function( ) {}, /** @return {Number} size of the current sample in bytes or -1 if no more samples are available. */ getSampleSize : function( ) {}, /**Returns the current sample's flags. */ getSampleFlags : function( ) {}, /**If the sample flags indicate that the current sample is at least partially encrypted, this call returns relevant information about the structure of the sample data required for decryption. @param {Object {MediaCodec.CryptoInfo}} info The android.media.MediaCodec.CryptoInfo structure to be filled in. @return {Boolean} true iff the sample flags contain {@link #SAMPLE_FLAG_ENCRYPTED} */ getSampleCryptoInfo : function( ) {}, /**Returns an estimate of how much data is presently cached in memory expressed in microseconds. Returns -1 if that information is unavailable or not applicable (no cache). */ getCachedDuration : function( ) {}, /**Returns true iff we are caching data and the cache has reached the end of the data stream (for now, a future seek may of course restart the fetching of data). This API only returns a meaningful result if {@link #getCachedDuration} indicates the presence of a cache, i.e. does NOT return -1. */ hasCacheReachedEndOfStream : function( ) {}, /**Return Metrics data about the current media container. @return {Object {android.os.PersistableBundle}} a {@link PersistableBundle} containing the set of attributes and values available for the media container being handled by this instance of MediaExtractor. The attributes are descibed in {@link MetricsConstants}. Additional vendor-specific fields may also be present in the return value. */ getMetrics : function( ) {}, };