IT. Expert System.

Android Reference


Class MediaExtractor

  • public final class MediaExtractor
    extends Object
    MediaExtractor facilitates extraction of demuxed, typically encoded, media data from a data source.

    It is generally used like this:

     MediaExtractor extractor = new MediaExtractor();
     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) {
     ByteBuffer inputBuffer = ByteBuffer.allocate(...)
     while (extractor.readSampleData(inputBuffer, ...) >= 0) {
       int trackIndex = extractor.getSampleTrackIndex();
       long presentationTimeUs = extractor.getSampleTime();
     extractor = null;
    • Constructor Detail

      • MediaExtractor

        public MediaExtractor()
    • Method Detail

      • setDataSource

        public final void setDataSource(DataSource source)
        Sets the DataSource object to be used as the data source for this extractor
      • setDataSource

        public final void setDataSource(Context context,
                         Uri uri,
                         Map<String,String> headers)
                                 throws IOException
        Sets the data source as a content Uri.
        context - the Context to use when resolving the Uri
        uri - the Content URI of the data you want to extract from.
        headers - the headers to be sent together with the request for the data
      • setDataSource

        public final void setDataSource(String path,
                         Map<String,String> headers)
        Sets the data source (file-path or http URL) to use.
        path - the path of the file, or the http URL
        headers - the headers associated with the http request for the stream you want to play
      • setDataSource

        public final void setDataSource(String path)
        Sets the data source (file-path or http URL) to use.
        path - the path of the file, or the http URL of the stream

        When path 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 setDataSource(FileDescriptor).

      • setDataSource

        public final void setDataSource(FileDescriptor fd)
        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.
        fd - the FileDescriptor for the file you want to extract from.
      • setDataSource

        public final void setDataSource(FileDescriptor fd,
                         long offset,
                         long length)
        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.
        fd - the FileDescriptor for the file you want to extract from.
        offset - the offset into the file where the data to be extracted starts, in bytes
        length - the length in bytes of the data to be extracted
      • finalize

        protected void finalize()
        Description copied from class: Object
        Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

        Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

        If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

        Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

        Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

        finalize in class Object
      • release

        public final void release()
        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.
      • getTrackCount

        public final int getTrackCount()
        Count the number of tracks found in the data source.
      • getTrackFormat

        public MediaFormat getTrackFormat(int index)
        Get the track format at the specified index. More detail on the representation can be found at MediaCodec
      • seekTo

        public void seekTo(long timeUs,
                  int mode)
        All selected tracks seek near the requested time according to the specified mode.
      • advance

        public boolean advance()
        Advance to the next sample. Returns false if no more sample data is available (end of stream).
      • readSampleData

        public int readSampleData(ByteBuffer byteBuf,
                         int offset)
        Retrieve the current encoded sample and store it in the byte buffer starting at the given offset. Returns the sample size (or -1 if no more samples are available).
      • getSampleTrackIndex

        public int getSampleTrackIndex()
        Returns the track index the current sample originates from (or -1 if no more samples are available)
      • getSampleTime

        public long getSampleTime()
        Returns the current sample's presentation time in microseconds. or -1 if no more samples are available.
      • getSampleFlags

        public int getSampleFlags()
        Returns the current sample's flags.
      • getSampleCryptoInfo

        public boolean getSampleCryptoInfo(MediaCodec.CryptoInfo info)
        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.
        info - The structure to be filled in.
        true iff the sample flags contain SAMPLE_FLAG_ENCRYPTED
      • getCachedDuration

        public long getCachedDuration()
        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).
      • hasCacheReachedEndOfStream

        public boolean hasCacheReachedEndOfStream()
        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 getCachedDuration() indicates the presence of a cache, i.e. does NOT return -1.


Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)





Java Script








Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 411 / 159176915. Delta: 0.04755 с