Using Mediaextractor to Read Mp3 Files Android

Course Overview

MediaExtractor facilitates extraction of demuxed, typically encoded, media data from a data source.

Information technology is generally used like this:

            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.accelerate();  }   extractor.release();  extractor = nix;          

Summary

Constants
int SAMPLE_FLAG_ENCRYPTED The sample is (at least partially) encrypted, come across too the documentation for queueSecureInputBuffer(int, int, MediaCodec.CryptoInfo, long, int)
int SAMPLE_FLAG_SYNC The sample is a sync sample
int SEEK_TO_CLOSEST_SYNC If possible, seek to the sync sample closest to the specified time
int SEEK_TO_NEXT_SYNC If possible, seek to a sync sample at or after the specified fourth dimension
int SEEK_TO_PREVIOUS_SYNC If possible, seek to a sync sample at or before the specified time
Public Constructors
MediaExtractor()
Public Methods
boolean accelerate()

Accelerate to the next sample.

long getCachedDuration()

Returns an estimate of how much information is presently cached in retentiveness expressed in microseconds.

Map<UUID, byte[]> getPsshInfo()

Become the PSSH info if present.

boolean getSampleCryptoInfo(MediaCodec.CryptoInfo info)

If the sample flags indicate that the current sample is at to the lowest degree partially encrypted, this call returns relevant information most the construction of the sample information required for decryption.

int getSampleFlags()

Returns the current sample's flags.

long getSampleTime()

Returns the current sample's presentation time in microseconds.

int getSampleTrackIndex()

Returns the track alphabetize the current sample originates from (or -1 if no more samples are bachelor)

concluding int getTrackCount()

Count the number of tracks found in the data source.

MediaFormat getTrackFormat(int alphabetize)

Get the track format at the specified index.

boolean hasCacheReachedEndOfStream()

Returns true iff we are caching data and the cache has reached the stop of the data stream (for now, a future seek may of course restart the fetching of data).

int readSampleData(ByteBuffer byteBuf, int offset)

Retrieve the electric current encoded sample and store it in the byte buffer starting at the given offset.

terminal void release()

Make certain you lot call this when you're done to free upwards any resources instead of relying on the garbage collector to do this for y'all at some point in the future.

void seekTo(long timeUs, int mode)

All selected tracks seek about the requested fourth dimension according to the specified mode.

void selectTrack(int index)

Subsequent calls to readSampleData(ByteBuffer, int), getSampleTrackIndex() and getSampleTime() only retrieve information for the subset of tracks selected.

final void setDataSource(Cord path)

Sets the data source (file-path or http URL) to utilize.

final void setDataSource(String path, Map<String, Cord> headers)

Sets the data source (file-path or http URL) to use.

terminal void setDataSource(FileDescriptor fd)

Sets the data source (FileDescriptor) to apply.

final void setDataSource(FileDescriptor fd, long kickoff, long length)

Sets the data source (FileDescriptor) to use.

final void setDataSource(Context context, Uri uri, Map<Cord, Cord> headers)

Sets the data source equally a content Uri.

void unselectTrack(int index)

Subsequent calls to readSampleData(ByteBuffer, int), getSampleTrackIndex() and getSampleTime() only retrieve data for the subset of tracks selected.

Protected Methods
void finalize()

Invoked when the garbage collector has detected that this instance is no longer reachable.

[Aggrandize]

Inherited Methods

From class java.lang.Object
Object clone()

Creates and returns a copy of this Object.

boolean equals(Object o)

Compares this example with the specified object and indicates if they are equal.

void finalize()

Invoked when the garbage collector has detected that this instance is no longer reachable.

final Class<?> getClass()

Returns the unique example of Class that represents this object's class.

int hashCode()

Returns an integer hash lawmaking for this object.

final void notify()

Causes a thread which is waiting on this object's monitor (past means of calling one of the await() methods) to be woken up.

final void notifyAll()

Causes all threads which are waiting on this object'south monitor (past ways of calling one of the wait() methods) to be woken up.

String toString()

Returns a string containing a concise, human-readable description of this object.

final void wait()

Causes the calling thread to expect until some other thread calls the notify() or notifyAll() method of this object.

final void wait(long millis, int nanos)

Causes the calling thread to await until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

terminal void look(long millis)

Causes the calling thread to look until some other thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

Constants

public static concluding int SAMPLE_FLAG_ENCRYPTED

Constant Value: two (0x00000002)

public static final int SAMPLE_FLAG_SYNC

The sample is a sync sample

Constant Value: 1 (0x00000001)

public static concluding int SEEK_TO_CLOSEST_SYNC

If possible, seek to the sync sample closest to the specified time

Constant Value: two (0x00000002)

public static fina 50 int SEEK_TO_NEXT_SYNC

If possible, seek to a sync sample at or after the specified time

Constant Value: 1 (0x00000001)

public static final int SEEK_TO_PREVIOUS_SYNC

If possible, seek to a sync sample at or before the specified time

Constant Value: 0 (0x00000000)

Public Constructors

public MediaExtractor ()

Public Methods

public boolean advance ()

Advance to the next sample. Returns simulated if no more sample information is available (end of stream).

public long getCachedDuration ()

Returns an estimate of how much data is presently buried in retentivity expressed in microseconds. Returns -i if that information is unavailable or not applicable (no cache).

public Map<UUID, byte[]> getPsshInfo ()

Get the PSSH info if present.

Returns
  • a map of uuid-to-bytes, with the uuid specifying the crypto scheme, and the bytes being the information specific to that scheme.

public boolean getSampleCryptoInfo (MediaCodec.CryptoInfo info)

If the sample flags indicate that the electric current sample is at least partially encrypted, this call returns relevant information virtually the structure of the sample data required for decryption.

Parameters
info The android.media.MediaCodec.CryptoInfo construction to be filled in.

public int getSampleFlags ()

Returns the electric current sample's flags.

public long getSampleTime ()

Returns the current sample'southward presentation time in microseconds. or -1 if no more samples are available.

public int getSampleTrackIndex ()

Returns the rails index t he current sample originates from (or -one if no more samples are bachelor)

public terminal int getTrackCount ()

Count the number of tracks found in the information source.

public MediaFormat getTrackFormat (int alphabetize)

Become the track format at the specified index. More detail on the representation can be establish at MediaCodec

public boolean hasCacheReachedEndOfStream ()

Returns true iff we are caching information and the cache has reached the end of the data stream (for now, a time to come seek may of course restart the fetching of data). This API only returns a meaningful outcome if getCachedDuration() indicates the presence of a enshroud, i.due east. does NOT return -one.

public int readSampleData (ByteBuffer byteBuf, int offset)

Call back the electric current encoded sample and store it in the byte buffer starting at the given showtime. Returns the sample size (or -1 if no more samples are available).

public final void release ()

Make certain you call this when y'all're washed to gratuitous upward any resources instead of relying on the garbage collector to practise this for you at some point in the futurity.

public void seekTo (long timeUs, int mode)

All selected tracks seek near the requested time according to the specified mode.

public void selectTrack (int index)

public final void setDataSource (String path)

Sets the information source (file-path or http URL) to use.

Parameters
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 past a process other than the calling awarding. This implies that the pathname should be an absolute path (equally 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 get-go open the file for reading, then employ the file descriptor course setDataSource(FileDescriptor).

public terminal void setDataSource (Cord path, Map<Cord, Cord> headers)

Sets the information source (file-path or http URL) to utilise.

Parameters
path the path of the file, or the http URL
headers the headers associated with the http request for the stream yous desire to play

public final void setDataSource (FileDescriptor fd)

Sets the data source (FileDescriptor) to utilize. It is the caller's responsibility to shut the file descriptor. It is safe to practise and then as presently equally this call returns.

Parameters
fd the FileDescriptor for the file you want to extract from.

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). Information technology is the caller'south responsibleness to close the file descriptor. It is condom to exercise so equally shortly as this call returns.

Parameters
fd the FileDescriptor for the file you desire to extract from.
offset the offset into the file where the data to exist extracted starts, in bytes
length the length in bytes of the data to be extracted

public final void setDataSource (Context context, Uri uri, Map<String, String> headers)

Sets the data source equally a content Uri.

Parameters
context the Context to use when resolving the Uri
uri the Content URI of the data yous desire to extract from.
headers the headers to be sent together with the request for the data

public void unselectTrack (int index)

Protected Methods

protected void finalize ()

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 exist run a long time after the object is no longer reachable, depending on retention pressure, and so information technology's a bad thought to rely on them for cleanup. Note likewise that finalizers are run on a unmarried VM-wide finalizer thread, then 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 telephone call a native method to destroy that peer. Fifty-fifty then, it'southward amend 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 bargain 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. Y'all are responsible for calling super.finalize() yourself.

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

bassettaredle.blogspot.com

Source: https://spot.pcc.edu/~mgoodman/developer.android.com/reference/android/media/MediaExtractor.html

0 Response to "Using Mediaextractor to Read Mp3 Files Android"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel