Android Guides | Samples

Android.Media.MediaExtractor Class

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

See Also: MediaExtractor

Syntax

[Android.Runtime.Register("android/media/MediaExtractor", DoNotGenerateAcw=true)]
public sealed class MediaExtractor : Object

Remarks

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

It is generally used like this:

java Example

 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;

[Android Documentation]

Requirements

Namespace: Android.Media
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 16

The members of Android.Media.MediaExtractor are listed below.

See Also: Object

Public Constructors

Public Fields

const
SampleFlagEncryptedMediaExtractorSampleFlags (2). The sample is (at least partially) encrypted, see also the documentation for MediaCodec.QueueSecureInputBuffer(Int32,Int32,Int32,Int32,Int32)
const
SampleFlagSyncMediaExtractorSampleFlags (1). The sample is a sync sample (or in MediaCodec's terminology it is a key frame.
const
SeekToClosestSyncMediaExtractorSeekTo (2). If possible, seek to the sync sample closest to the specified time
const
SeekToNextSyncMediaExtractorSeekTo (1). If possible, seek to a sync sample at or after the specified time
const
SeekToPreviousSyncMediaExtractorSeekTo (0). If possible, seek to a sync sample at or before the specified time

Public Properties

[read-only]
CachedDurationInt64. Returns an estimate of how much data is presently cached in memory expressed in microseconds.
[read-only]
HasCacheReachedEndOfStreamBoolean. 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).
[read-only]
PsshInfoIDictionary<Java.Util.UUID, Byte[]>. Get the PSSH info if present.
[read-only]
SampleFlagsMediaExtractorSampleFlags. Returns the current sample's flags.
[read-only]
SampleTimeInt64. Returns the current sample's presentation time in microseconds. or -1 if no more samples are available.
[read-only]
SampleTrackIndexInt32. Returns the track index the current sample originates from (or -1 if no more samples are available)
[read-only]
TrackCountInt32. Count the number of tracks found in the data source.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

Advance() : Boolean
Advance to the next sample.
AdvanceAsync() : System.Threading.Tasks.Task<bool>
GetSampleCryptoInfo(MediaCodec+CryptoInfo) : Boolean
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.
GetTrackFormat(Int32) : MediaFormat
Get the track format at the specified index.
ReadSampleData(ByteBuffer, Int32) : Int32
Retrieve the current encoded sample and store it in the byte buffer starting at the given offset.
ReadSampleDataAsync(ByteBuffer, Int32) : System.Threading.Tasks.Task<int>
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.
SeekTo(Int64, MediaExtractorSeekTo)
All selected tracks seek near the requested time according to the specified mode.
SelectTrack(Int32)
Subsequent calls to MediaExtractor.ReadSampleData(ByteBuffer,Int32), MediaExtractor.SampleTrackIndex and MediaExtractor.SampleTime only retrieve information for the subset of tracks selected.
SetDataSource(FileDescriptor)
Sets the data source (FileDescriptor) to use.
SetDataSource(String)
Sets the data source (file-path or http URL) to use.
SetDataSource(String, IDictionary<string, string>)
SetDataSource(Context, Uri, IDictionary<string, string>)
SetDataSource(FileDescriptor, Int64, Int64)
Sets the data source (FileDescriptor) to use.
SetDataSourceAsync(FileDescriptor) : Task
SetDataSourceAsync(String) : Task
SetDataSourceAsync(String, IDictionary<string, string>) : Task
SetDataSourceAsync(Context, Uri, IDictionary<string, string>) : Task
SetDataSourceAsync(FileDescriptor, Int64, Int64) : Task
UnselectTrack(Int32)
Subsequent calls to MediaExtractor.ReadSampleData(ByteBuffer,Int32), MediaExtractor.SampleTrackIndex and MediaExtractor.SampleTime only retrieve information for the subset of tracks selected.