# MediaExtractorCompat

Artifact: [androidx.media3:media3-inspector](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/inspector/MediaExtractorCompat.java+class:androidx.media3.inspector.MediaExtractorCompat)

*** ** * ** ***


```
@UnstableApi
public final class MediaExtractorCompat
```

<br />

*** ** * ** ***

A drop-in replacement for `https://developer.android.com/reference/android/media/MediaExtractor.html` that provides similar functionality, based on the `media3.extractor` logic.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/androidx/annotation/IntDef(value = ) @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) public annotation https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat.SeekMode` The seeking mode. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#SEEK_TO_CLOSEST_SYNC() = 2` See `https://developer.android.com/reference/android/media/MediaExtractor.html#SEEK_TO_CLOSEST_SYNC`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#SEEK_TO_NEXT_SYNC() = 1` See `https://developer.android.com/reference/android/media/MediaExtractor.html#SEEK_TO_NEXT_SYNC`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#SEEK_TO_PREVIOUS_SYNC() = 0` See `https://developer.android.com/reference/android/media/MediaExtractor.html#SEEK_TO_PREVIOUS_SYNC`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat()()` Creates a new instance using a `https://developer.android.com/reference/androidx/media3/extractor/DefaultExtractorsFactory` and a default `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory` that supports local files and HTTP/HTTPS streams. |
| `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat(android.content.Context)(https://developer.android.com/reference/android/content/Context.html context)` Creates a new instance using a `https://developer.android.com/reference/androidx/media3/extractor/DefaultExtractorsFactory` and a `https://developer.android.com/reference/androidx/media3/datasource/DefaultDataSource.Factory` configured with the given `https://developer.android.com/reference/android/content/Context.html`. |
| `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat(androidx.media3.exoplayer.source.ProgressiveMediaExtractor)( https://developer.android.com/reference/androidx/media3/exoplayer/source/ProgressiveMediaExtractor progressiveMediaExtractor )` Creates a new instance using the given `https://developer.android.com/reference/androidx/media3/exoplayer/source/ProgressiveMediaExtractor` and a default `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory` that supports local files and HTTP/HTTPS streams. |
| `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat(androidx.media3.extractor.ExtractorsFactory,androidx.media3.datasource.DataSource.Factory)( https://developer.android.com/reference/androidx/media3/extractor/ExtractorsFactory extractorsFactory, https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory dataSourceFactory )` Creates a new instance using the given `https://developer.android.com/reference/androidx/media3/extractor/ExtractorsFactory` to create the `https://developer.android.com/reference/androidx/media3/extractor/Extractor` to use for obtaining media samples from a `https://developer.android.com/reference/androidx/media3/datasource/DataSource` generated by the given `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory`. |
| `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat(androidx.media3.exoplayer.source.ProgressiveMediaExtractor,androidx.media3.datasource.DataSource.Factory)( https://developer.android.com/reference/androidx/media3/exoplayer/source/ProgressiveMediaExtractor progressiveMediaExtractor, https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory dataSourceFactory )` Creates a new instance using the given `https://developer.android.com/reference/androidx/media3/exoplayer/source/ProgressiveMediaExtractor` to obtain media samples from a `https://developer.android.com/reference/androidx/media3/datasource/DataSource` generated by the given `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory`. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#advance()()` Advances to the next sample. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator` | `@https://developer.android.com/reference/androidx/annotation/VisibleForTesting(otherwise = 5) https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getAllocator()()` |
| `long` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getCachedDuration()()` Returns an estimate of how much data is presently cached in memory, expressed in microseconds, or -1 if this information is unavailable or not applicable (i.e., no cache exists). |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/DrmInitData` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getDrmInitData()()` Extracts the DRM initialization data from the available tracks, if it exists. |
| `https://developer.android.com/reference/android/media/metrics/LogSessionId.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 31) https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getLogSessionId()()` Returns the `https://developer.android.com/reference/android/media/metrics/LogSessionId.html` for MediaExtractorCompat. |
| `https://developer.android.com/reference/android/os/PersistableBundle.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getMetrics()()` Returns a `https://developer.android.com/reference/android/os/PersistableBundle.html` containing metrics data for the current media container. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/util/UUID.html, byte[]>` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getPsshInfo()()` Extracts PSSH data from the media, if present. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getSampleCryptoInfo(android.media.MediaCodec.CryptoInfo)(https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.html info)` Returns `true` if the current sample is at least partially encrypted and fills the provided `https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.html` structure with relevant decryption information. |
| `int` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getSampleFlags()()` Returns the current sample's flags. |
| `long` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getSampleSize()()` Returns the current sample's size in bytes, or -1 if no more samples are available. |
| `long` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getSampleTime()()` Returns the current sample's presentation time in microseconds, or -1 if no more samples are available. |
| `int` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getSampleTrackIndex()()` Returns the track index the current sample originates from, or -1 if no more samples are available. |
| `int` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getTrackCount()()` Returns the number of tracks found in the data source. |
| `https://developer.android.com/reference/android/media/MediaFormat.html` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getTrackFormat(int)(int trackIndex)` Returns the track `https://developer.android.com/reference/android/media/MediaFormat.html` at the specified `trackIndex`. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#hasCacheReachedEndOfStream()()` Returns `true` if data is being cached and the cache has reached the end of the data stream. |
| `int` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#readSampleData(java.nio.ByteBuffer,int)(https://developer.android.com/reference/java/nio/ByteBuffer.html buffer, int offset)` Retrieves the current encoded sample and stores it in the byte `buffer` starting at the given `offset`. |
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#release()()` Releases any resources held by this instance. |
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#seekTo(long,int)(long timeUs, @https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat.SeekMode int mode)` All selected tracks seek near the requested `timeUs` according to the specified ` mode`. |
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#selectTrack(int)(int trackIndex)` Selects a track at the specified `trackIndex`. |
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.content.res.AssetFileDescriptor)(https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html assetFileDescriptor)` Sets the data source using the media stream obtained from the provided `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html`. |
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(java.io.FileDescriptor)(https://developer.android.com/reference/java/io/FileDescriptor.html fileDescriptor)` Sets the data source using the media stream obtained from the provided `https://developer.android.com/reference/java/io/FileDescriptor.html`. |
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.media.MediaDataSource)(https://developer.android.com/reference/android/media/MediaDataSource.html mediaDataSource)` Sets the data source using the media stream obtained from the given `https://developer.android.com/reference/android/media/MediaDataSource.html`. |
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(java.lang.String)(https://developer.android.com/reference/java/lang/String.html path)` Sets the data source using the media stream obtained from the given file path or HTTP URL. |
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(java.lang.String,java.util.Map<java.lang.String,java.lang.String>)(https://developer.android.com/reference/java/lang/String.html path, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html> headers)` Sets the data source using the media stream obtained from the given file path or HTTP URL, with optional HTTP request headers. |
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.net.Uri,long)(https://developer.android.com/reference/android/net/Uri.html uri, long offset)` Sets the data source using the media stream obtained from the given `https://developer.android.com/reference/android/net/Uri.html` at the given `offset`. |
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.content.Context,android.net.Uri,java.util.Map<java.lang.String,java.lang.String>)( https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/android/net/Uri.html uri, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html> headers )` Sets the data source using the media stream obtained from the given `https://developer.android.com/reference/android/net/Uri.html` and optional HTTP request headers. |
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(java.io.FileDescriptor,long,long)(https://developer.android.com/reference/java/io/FileDescriptor.html fileDescriptor, long offset, long length)` Sets the data source using the media stream obtained from the provided `https://developer.android.com/reference/java/io/FileDescriptor.html`, with a specified `offset` and `length`. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 31) https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setLogSessionId(android.media.metrics.LogSessionId)(https://developer.android.com/reference/android/media/metrics/LogSessionId.html logSessionId)` Sets the `https://developer.android.com/reference/android/media/metrics/LogSessionId.html` for MediaExtractorCompat. |
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#unselectTrack(int)(int trackIndex)` Unselects the track at the specified `trackIndex`. |

## Constants

### SEEK_TO_CLOSEST_SYNC

```
public static final int SEEK_TO_CLOSEST_SYNC = 2
```

See `https://developer.android.com/reference/android/media/MediaExtractor.html#SEEK_TO_CLOSEST_SYNC`.

### SEEK_TO_NEXT_SYNC

```
public static final int SEEK_TO_NEXT_SYNC = 1
```

See `https://developer.android.com/reference/android/media/MediaExtractor.html#SEEK_TO_NEXT_SYNC`.

### SEEK_TO_PREVIOUS_SYNC

```
public static final int SEEK_TO_PREVIOUS_SYNC = 0
```

See `https://developer.android.com/reference/android/media/MediaExtractor.html#SEEK_TO_PREVIOUS_SYNC`.

## Public constructors

### MediaExtractorCompat

```
public MediaExtractorCompat()
```

Creates a new instance using a `https://developer.android.com/reference/androidx/media3/extractor/DefaultExtractorsFactory` and a default `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory` that supports local files and HTTP/HTTPS streams.

Note: Without a `https://developer.android.com/reference/android/content/Context.html`, `content://` and `android.resource://` URIs are only supported via `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.content.Context,android.net.Uri,java.util.Map<java.lang.String,java.lang.String>)`. For full `https://developer.android.com/reference/androidx/media3/datasource/DefaultDataSource` support (including `asset://` URIs), use `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat(android.content.Context)`.

### MediaExtractorCompat

```
public MediaExtractorCompat(Context context)
```

Creates a new instance using a `https://developer.android.com/reference/androidx/media3/extractor/DefaultExtractorsFactory` and a `https://developer.android.com/reference/androidx/media3/datasource/DefaultDataSource.Factory` configured with the given `https://developer.android.com/reference/android/content/Context.html`.

### MediaExtractorCompat

```
public MediaExtractorCompat(
    ProgressiveMediaExtractor progressiveMediaExtractor
)
```

Creates a new instance using the given `https://developer.android.com/reference/androidx/media3/exoplayer/source/ProgressiveMediaExtractor` and a default `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory` that supports local files and HTTP/HTTPS streams.

Note: Without a `https://developer.android.com/reference/android/content/Context.html`, `content://` and `android.resource://` URIs are only supported via `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.content.Context,android.net.Uri,java.util.Map<java.lang.String,java.lang.String>)`. For full `https://developer.android.com/reference/androidx/media3/datasource/DefaultDataSource` support (including `asset://` URIs), use `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat(androidx.media3.exoplayer.source.ProgressiveMediaExtractor,androidx.media3.datasource.DataSource.Factory)` with a `https://developer.android.com/reference/androidx/media3/datasource/DefaultDataSource.Factory`.

### MediaExtractorCompat

```
public MediaExtractorCompat(
    ExtractorsFactory extractorsFactory,
    DataSource.Factory dataSourceFactory
)
```

Creates a new instance using the given `https://developer.android.com/reference/androidx/media3/extractor/ExtractorsFactory` to create the `https://developer.android.com/reference/androidx/media3/extractor/Extractor` to use for obtaining media samples from a `https://developer.android.com/reference/androidx/media3/datasource/DataSource` generated by the given `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory`.

Note: The `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory` provided will not be used to generate `https://developer.android.com/reference/androidx/media3/datasource/DataSource` when setting data source using methods:

- `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.content.res.AssetFileDescriptor)`
- `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(java.io.FileDescriptor)`
- `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(java.io.FileDescriptor,long,long)`

Note: The `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory` provided may not be used to generate `https://developer.android.com/reference/androidx/media3/datasource/DataSource` when setting data source using method `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.content.Context,android.net.Uri,java.util.Map<java.lang.String,java.lang.String>)` as the behavior depends on the fallthrough logic related to the scheme of the provided URI.

### MediaExtractorCompat

```
public MediaExtractorCompat(
    ProgressiveMediaExtractor progressiveMediaExtractor,
    DataSource.Factory dataSourceFactory
)
```

Creates a new instance using the given `https://developer.android.com/reference/androidx/media3/exoplayer/source/ProgressiveMediaExtractor` to obtain media samples from a `https://developer.android.com/reference/androidx/media3/datasource/DataSource` generated by the given `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory`.

Note: The `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory` provided will not be used to generate `https://developer.android.com/reference/androidx/media3/datasource/DataSource` when setting data source using methods:

- `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.content.res.AssetFileDescriptor)`
- `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(java.io.FileDescriptor)`
- `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(java.io.FileDescriptor,long,long)`

Note: The `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory` provided may not be used to generate `https://developer.android.com/reference/androidx/media3/datasource/DataSource` when setting data source using method `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.content.Context,android.net.Uri,java.util.Map<java.lang.String,java.lang.String>)` as the behavior depends on the fallthrough logic related to the scheme of the provided URI.

## Public methods

### advance

```
public boolean advance()
```

Advances to the next sample. Returns `false` if no more sample data is available (i.e., end of stream), or `true` otherwise.

Note: When extracting from a local file, the behavior of `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#advance()` and `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#readSampleData(java.nio.ByteBuffer,int)` is undefined if there are concurrent writes to the same file. This may result in an unexpected end of stream being signaled.

### getAllocator

```
@VisibleForTesting(otherwise = 5)
public Allocator getAllocator()
```

### getCachedDuration

```
public long getCachedDuration()
```

Returns an estimate of how much data is presently cached in memory, expressed in microseconds, or -1 if this information is unavailable or not applicable (i.e., no cache exists).

### getDrmInitData

```
public @Nullable DrmInitData getDrmInitData()
```

Extracts the DRM initialization data from the available tracks, if it exists.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/DrmInitData` | The `https://developer.android.com/reference/androidx/media3/common/DrmInitData` in the content, or `null` if no recognizable DRM format is found. |

### getLogSessionId

```
@RequiresApi(value = 31)
public LogSessionId getLogSessionId()
```

Returns the `https://developer.android.com/reference/android/media/metrics/LogSessionId.html` for MediaExtractorCompat.

### getMetrics

```
@RequiresApi(value = 26)
public PersistableBundle getMetrics()
```

Returns a `https://developer.android.com/reference/android/os/PersistableBundle.html` containing metrics data for the current media container.

The bundle includes attributes and values for the media container, as described in `https://developer.android.com/reference/android/media/MediaExtractor.MetricsConstants.html`.

### getPsshInfo

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

Extracts PSSH data from the media, if present.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/util/UUID.html, byte[]>` | A `https://developer.android.com/reference/java/util/Map.html` of UUID-to-byte\[\] pairs, where the `https://developer.android.com/reference/java/util/UUID.html` identifies the crypto scheme, and the byte array contains the scheme-specific data. Returns `null` if no PSSH data exists. |

### getSampleCryptoInfo

```
public boolean getSampleCryptoInfo(MediaCodec.CryptoInfo info)
```

Returns `true` if the current sample is at least partially encrypted and fills the provided `https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.html` structure with relevant decryption information.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.html info` | The `https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.html` structure to be filled with decryption data. |

| Returns |
|---|---|
| `boolean` | `true` if the sample is at least partially encrypted, `false` otherwise. |

### getSampleFlags

```
public int getSampleFlags()
```

Returns the current sample's flags.

### getSampleSize

```
public long getSampleSize()
```

Returns the current sample's size in bytes, 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.

### getSampleTrackIndex

```
public int getSampleTrackIndex()
```

Returns the track index the current sample originates from, or -1 if no more samples are available.

### getTrackCount

```
public int getTrackCount()
```

Returns the number of tracks found in the data source.

### getTrackFormat

```
public MediaFormat getTrackFormat(int trackIndex)
```

Returns the track `https://developer.android.com/reference/android/media/MediaFormat.html` at the specified `trackIndex`.

### hasCacheReachedEndOfStream

```
public boolean hasCacheReachedEndOfStream()
```

Returns `true` if data is being cached and the cache has reached the end of the data stream. This indicates that no additional data is currently available for caching, although a future seek may restart data fetching. This method only returns a meaningful result if `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getCachedDuration()` indicates the presence of a cache (i.e., does not return -1).

### readSampleData

```
public int readSampleData(ByteBuffer buffer, int offset)
```

Retrieves the current encoded sample and stores it in the byte `buffer` starting at the given `offset`.

**Note:** On success, the position and limit of `buffer` is updated to point to the data just read.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html buffer` | the destination byte buffer. |
| `int offset` | The offset into the byte buffer at which to write. |

| Returns |
|---|---|
| `int` | the sample size, or -1 if no more samples are available. |

### release

```
public void release()
```

Releases any resources held by this instance.

Note: 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

```
public void seekTo(long timeUs, @MediaExtractorCompat.SeekMode int mode)
```

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

### selectTrack

```
public void selectTrack(int trackIndex)
```

Selects a track at the specified `trackIndex`.

Subsequent calls to `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#readSampleData(java.nio.ByteBuffer,int)`, `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getSampleTrackIndex()` and `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getSampleTime()` only retrieve information for the subset of tracks selected.

Note: Selecting the same track multiple times has no effect, the track is only selected once.

### setDataSource

```
public void setDataSource(AssetFileDescriptor assetFileDescriptor)
```

Sets the data source using the media stream obtained from the provided `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html`.

Note: The caller is responsible for closing the `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html`. It is safe to do so immediately after this method returns.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html assetFileDescriptor` | The `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html` for the file to extract from. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs while extracting the media. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/UnrecognizedInputFormatException` | If none of the available extractors successfully sniffs the input. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called twice on the same instance. |

### setDataSource

```
public void setDataSource(FileDescriptor fileDescriptor)
```

Sets the data source using the media stream obtained from the provided `https://developer.android.com/reference/java/io/FileDescriptor.html`.

Note: The caller is responsible for closing the `https://developer.android.com/reference/java/io/FileDescriptor.html`. It is safe to do so immediately after this method returns.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/io/FileDescriptor.html fileDescriptor` | The `https://developer.android.com/reference/java/io/FileDescriptor.html` for the file to extract from. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs while extracting the media. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/UnrecognizedInputFormatException` | If none of the available extractors successfully sniffs the input. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called twice on the same instance. |

### setDataSource

```
public void setDataSource(MediaDataSource mediaDataSource)
```

Sets the data source using the media stream obtained from the given `https://developer.android.com/reference/android/media/MediaDataSource.html`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/media/MediaDataSource.html mediaDataSource` | The `https://developer.android.com/reference/android/media/MediaDataSource.html` to extract media from. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs while extracting the media. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/UnrecognizedInputFormatException` | If none of the available extractors successfully sniffs the input. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called twice on the same instance. |

### setDataSource

```
public void setDataSource(String path)
```

Sets the data source using the media stream obtained from the given file path or HTTP URL.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html path` | The path of the file, or the HTTP URL, to extract media from. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs while extracting the media. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/UnrecognizedInputFormatException` | If none of the available extractors successfully sniffs the input. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called twice on the same instance. |

### setDataSource

```
public void setDataSource(String path, @Nullable Map<String, String> headers)
```

Sets the data source using the media stream obtained from the given file path or HTTP URL, with optional HTTP request headers.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html path` | The path of the file, or the HTTP URL, to extract media from. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html> headers` | An optional `https://developer.android.com/reference/java/util/Map.html` of HTTP request headers to include when fetching the data, or `null` if no headers are to be included. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs while extracting the media. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/UnrecognizedInputFormatException` | If none of the available extractors successfully sniffs the input. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called twice on the same instance. |

### setDataSource

```
public void setDataSource(Uri uri, long offset)
```

Sets the data source using the media stream obtained from the given `https://developer.android.com/reference/android/net/Uri.html` at the given `offset`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/net/Uri.html uri` | The content `https://developer.android.com/reference/android/net/Uri.html` to extract from. |
| `long offset` | The offset into the file where the data to be extracted starts, in bytes. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs while extracting the media. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/UnrecognizedInputFormatException` | If none of the available extractors successfully sniffs the input. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called twice on the same instance. |

### setDataSource

```
public void setDataSource(
    Context context,
    Uri uri,
    @Nullable Map<String, String> headers
)
```

Sets the data source using the media stream obtained from the given `https://developer.android.com/reference/android/net/Uri.html` and optional HTTP request headers.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | The `https://developer.android.com/reference/android/content/Context.html` used to resolve the `https://developer.android.com/reference/android/net/Uri.html`. |
| `https://developer.android.com/reference/android/net/Uri.html uri` | The `https://developer.android.com/reference/android/net/Uri.html` of the media to extract from. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html> headers` | An optional `https://developer.android.com/reference/java/util/Map.html` of HTTP request headers to include when fetching the data, or `null` if no headers are to be included. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs while extracting the media. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/UnrecognizedInputFormatException` | If none of the available extractors successfully sniffs the input. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called twice on the same instance. |

### setDataSource

```
public void setDataSource(FileDescriptor fileDescriptor, long offset, long length)
```

Sets the data source using the media stream obtained from the provided `https://developer.android.com/reference/java/io/FileDescriptor.html`, with a specified `offset` and `length`.

Note: The caller is responsible for closing the `https://developer.android.com/reference/java/io/FileDescriptor.html`. It is safe to do so immediately after this method returns.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/io/FileDescriptor.html fileDescriptor` | The `https://developer.android.com/reference/java/io/FileDescriptor.html` for the file to extract from. |
| `long offset` | The offset into the file where the data to be extracted starts, in bytes. |
| `long length` | The length of the data to be extracted, in bytes, or `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` if it is unknown. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs while extracting the media. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/UnrecognizedInputFormatException` | If none of the available extractors successfully sniffs the input. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called twice on the same instance. |

### setLogSessionId

```
@RequiresApi(value = 31)
public void setLogSessionId(LogSessionId logSessionId)
```

Sets the `https://developer.android.com/reference/android/media/metrics/LogSessionId.html` for MediaExtractorCompat.

### unselectTrack

```
public void unselectTrack(int trackIndex)
```

Unselects the track at the specified `trackIndex`.

Subsequent calls to `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#readSampleData(java.nio.ByteBuffer,int)`, `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getSampleTrackIndex()` and `https://developer.android.com/reference/androidx/media3/inspector/MediaExtractorCompat#getSampleTime()` only retrieve information for the subset of tracks selected.