# 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
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/kotlin/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) annotation https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat.SeekMode` The seeking mode. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#SEEK_TO_CLOSEST_SYNC() = 2` See `https://developer.android.com/reference/android/media/MediaExtractor.html#SEEK_TO_CLOSEST_SYNC`. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#SEEK_TO_NEXT_SYNC() = 1` See `https://developer.android.com/reference/android/media/MediaExtractor.html#SEEK_TO_NEXT_SYNC`. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat()()` Creates a new instance using a `https://developer.android.com/reference/kotlin/androidx/media3/extractor/DefaultExtractorsFactory` and a default `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory` that supports local files and HTTP/HTTPS streams. |
| `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html!)` Creates a new instance using a `https://developer.android.com/reference/kotlin/androidx/media3/extractor/DefaultExtractorsFactory` and a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DefaultDataSource.Factory` configured with the given `https://developer.android.com/reference/android/content/Context.html`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat(androidx.media3.exoplayer.source.ProgressiveMediaExtractor)( progressiveMediaExtractor: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ProgressiveMediaExtractor! )` Creates a new instance using the given `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ProgressiveMediaExtractor` and a default `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory` that supports local files and HTTP/HTTPS streams. |
| `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat(androidx.media3.extractor.ExtractorsFactory,androidx.media3.datasource.DataSource.Factory)( extractorsFactory: https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorsFactory!, dataSourceFactory: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory! )` Creates a new instance using the given `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorsFactory` to create the `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Extractor` to use for obtaining media samples from a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` generated by the given `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat(androidx.media3.exoplayer.source.ProgressiveMediaExtractor,androidx.media3.datasource.DataSource.Factory)( progressiveMediaExtractor: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ProgressiveMediaExtractor!, dataSourceFactory: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory! )` Creates a new instance using the given `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ProgressiveMediaExtractor` to obtain media samples from a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` generated by the given `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory`. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#advance()()` Advances to the next sample. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator!` | `@https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting(otherwise = 5) https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#getAllocator()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/DrmInitData?` | `https://developer.android.com/reference/kotlin/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/kotlin/androidx/annotation/RequiresApi(value = 31) https://developer.android.com/reference/kotlin/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/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/kotlin/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://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://developer.android.com/reference/java/util/UUID.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!>?` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#getPsshInfo()()` Extracts PSSH data from the media, if present. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#getSampleCryptoInfo(android.media.MediaCodec.CryptoInfo)(info: https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.html!)` 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. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#getSampleFlags()()` Returns the current sample's flags. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#getSampleSize()()` Returns the current sample's size in bytes, or -1 if no more samples are available. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#getSampleTime()()` Returns the current sample's presentation time in microseconds, or -1 if no more samples are available. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#getSampleTrackIndex()()` Returns the track index the current sample originates from, or -1 if no more samples are available. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/inspector/MediaExtractorCompat#getTrackFormat(int)(trackIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the track `https://developer.android.com/reference/android/media/MediaFormat.html` at the specified `trackIndex`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#hasCacheReachedEndOfStream()()` Returns `true` if data is being cached and the cache has reached the end of the data stream. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#readSampleData(java.nio.ByteBuffer,int)(buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html!, offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Retrieves the current encoded sample and stores it in the byte `buffer` starting at the given `offset`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#release()()` Releases any resources held by this instance. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#seekTo(long,int)(timeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, @https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat.SeekMode mode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` All selected tracks seek near the requested `timeUs` according to the specified ` mode`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#selectTrack(int)(trackIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Selects a track at the specified `trackIndex`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.content.res.AssetFileDescriptor)(assetFileDescriptor: https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html!)` Sets the data source using the media stream obtained from the provided `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#setDataSource(java.io.FileDescriptor)(fileDescriptor: https://developer.android.com/reference/java/io/FileDescriptor.html!)` Sets the data source using the media stream obtained from the provided `https://developer.android.com/reference/java/io/FileDescriptor.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.media.MediaDataSource)(mediaDataSource: https://developer.android.com/reference/android/media/MediaDataSource.html!)` Sets the data source using the media stream obtained from the given `https://developer.android.com/reference/android/media/MediaDataSource.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#setDataSource(java.lang.String)(path: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Sets the data source using the media stream obtained from the given file path or HTTP URL. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#setDataSource(java.lang.String,java.util.Map<java.lang.String,java.lang.String>)(path: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, headers: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>?)` Sets the data source using the media stream obtained from the given file path or HTTP URL, with optional HTTP request headers. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.net.Uri,long)(uri: https://developer.android.com/reference/android/net/Uri.html!, offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` 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`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#setDataSource(android.content.Context,android.net.Uri,java.util.Map<java.lang.String,java.lang.String>)( context: https://developer.android.com/reference/android/content/Context.html!, uri: https://developer.android.com/reference/android/net/Uri.html!, headers: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>? )` 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. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#setDataSource(java.io.FileDescriptor,long,long)(fileDescriptor: https://developer.android.com/reference/java/io/FileDescriptor.html!, offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` 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`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 31) https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#setLogSessionId(android.media.metrics.LogSessionId)(logSessionId: https://developer.android.com/reference/android/media/metrics/LogSessionId.html!)` Sets the `https://developer.android.com/reference/android/media/metrics/LogSessionId.html` for MediaExtractorCompat. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#unselectTrack(int)(trackIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Unselects the track at the specified `trackIndex`. |

## Constants

### SEEK_TO_CLOSEST_SYNC

```
const val SEEK_TO_CLOSEST_SYNC = 2: Int
```

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

### SEEK_TO_NEXT_SYNC

```
const val SEEK_TO_NEXT_SYNC = 1: Int
```

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

### SEEK_TO_PREVIOUS_SYNC

```
const val SEEK_TO_PREVIOUS_SYNC = 0: Int
```

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

## Public constructors

### MediaExtractorCompat

```
MediaExtractorCompat()
```

Creates a new instance using a `https://developer.android.com/reference/kotlin/androidx/media3/extractor/DefaultExtractorsFactory` and a default `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/androidx/media3/datasource/DefaultDataSource` support (including `asset://` URIs), use `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat(android.content.Context)`.

### MediaExtractorCompat

```
MediaExtractorCompat(context: Context!)
```

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

### MediaExtractorCompat

```
MediaExtractorCompat(
    progressiveMediaExtractor: ProgressiveMediaExtractor!
)
```

Creates a new instance using the given `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ProgressiveMediaExtractor` and a default `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/androidx/media3/datasource/DefaultDataSource` support (including `asset://` URIs), use `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#MediaExtractorCompat(androidx.media3.exoplayer.source.ProgressiveMediaExtractor,androidx.media3.datasource.DataSource.Factory)` with a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DefaultDataSource.Factory`.

### MediaExtractorCompat

```
MediaExtractorCompat(
    extractorsFactory: ExtractorsFactory!,
    dataSourceFactory: DataSource.Factory!
)
```

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

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

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

Note: The `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory` provided may not be used to generate `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` when setting data source using method `https://developer.android.com/reference/kotlin/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

```
MediaExtractorCompat(
    progressiveMediaExtractor: ProgressiveMediaExtractor!,
    dataSourceFactory: DataSource.Factory!
)
```

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

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

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

Note: The `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory` provided may not be used to generate `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` when setting data source using method `https://developer.android.com/reference/kotlin/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 functions

### advance

```
fun advance(): Boolean
```

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/kotlin/androidx/media3/inspector/MediaExtractorCompat#advance()` and `https://developer.android.com/reference/kotlin/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)
fun getAllocator(): Allocator!
```

### getCachedDuration

```
fun getCachedDuration(): Long
```

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

```
fun getDrmInitData(): DrmInitData?
```

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

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

### getLogSessionId

```
@RequiresApi(value = 31)
fun getLogSessionId(): LogSessionId!
```

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

### getMetrics

```
@RequiresApi(value = 26)
fun getMetrics(): PersistableBundle!
```

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

```
fun getPsshInfo(): (Mutable)Map<UUID!, Array<Byte>!>?
```

Extracts PSSH data from the media, if present.

| Returns |
|---|---|
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://developer.android.com/reference/java/util/UUID.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!>?` | 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

```
fun getSampleCryptoInfo(info: MediaCodec.CryptoInfo!): Boolean
```

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 |
|---|---|
| `info: https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.html!` | The `https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.html` structure to be filled with decryption data. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the sample is at least partially encrypted, `false` otherwise. |

### getSampleFlags

```
fun getSampleFlags(): Int
```

Returns the current sample's flags.

### getSampleSize

```
fun getSampleSize(): Long
```

Returns the current sample's size in bytes, or -1 if no more samples are available.

### getSampleTime

```
fun getSampleTime(): Long
```

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

### getSampleTrackIndex

```
fun getSampleTrackIndex(): Int
```

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

### getTrackCount

```
fun getTrackCount(): Int
```

Returns the number of tracks found in the data source.

### getTrackFormat

```
fun getTrackFormat(trackIndex: Int): MediaFormat!
```

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

### hasCacheReachedEndOfStream

```
fun hasCacheReachedEndOfStream(): Boolean
```

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/kotlin/androidx/media3/inspector/MediaExtractorCompat#getCachedDuration()` indicates the presence of a cache (i.e., does not return -1).

### readSampleData

```
fun readSampleData(buffer: ByteBuffer!, offset: Int): Int
```

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 |
|---|---|
| `buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html!` | the destination byte buffer. |
| `offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The offset into the byte buffer at which to write. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the sample size, or -1 if no more samples are available. |

### release

```
fun release(): Unit
```

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

```
fun seekTo(timeUs: Long, @MediaExtractorCompat.SeekMode mode: Int): Unit
```

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

### selectTrack

```
fun selectTrack(trackIndex: Int): Unit
```

Selects a track at the specified `trackIndex`.

Subsequent calls to `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#readSampleData(java.nio.ByteBuffer,int)`, `https://developer.android.com/reference/kotlin/androidx/media3/inspector/MediaExtractorCompat#getSampleTrackIndex()` and `https://developer.android.com/reference/kotlin/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

```
fun setDataSource(assetFileDescriptor: AssetFileDescriptor!): Unit
```

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 |
|---|---|
| `assetFileDescriptor: https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html!` | 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/kotlin/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

```
fun setDataSource(fileDescriptor: FileDescriptor!): Unit
```

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 |
|---|---|
| `fileDescriptor: https://developer.android.com/reference/java/io/FileDescriptor.html!` | 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/kotlin/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

```
fun setDataSource(mediaDataSource: MediaDataSource!): Unit
```

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

| Parameters |
|---|---|
| `mediaDataSource: https://developer.android.com/reference/android/media/MediaDataSource.html!` | 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/kotlin/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

```
fun setDataSource(path: String!): Unit
```

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

| Parameters |
|---|---|
| `path: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | 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/kotlin/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

```
fun setDataSource(path: String!, headers: (Mutable)Map<String!, String!>?): Unit
```

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

| Parameters |
|---|---|
| `path: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The path of the file, or the HTTP URL, to extract media from. |
| `headers: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>?` | 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/kotlin/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

```
fun setDataSource(uri: Uri!, offset: Long): Unit
```

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 |
|---|---|
| `uri: https://developer.android.com/reference/android/net/Uri.html!` | The content `https://developer.android.com/reference/android/net/Uri.html` to extract from. |
| `offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | 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/kotlin/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

```
fun setDataSource(
    context: Context!,
    uri: Uri!,
    headers: (Mutable)Map<String!, String!>?
): Unit
```

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 |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html!` | The `https://developer.android.com/reference/android/content/Context.html` used to resolve the `https://developer.android.com/reference/android/net/Uri.html`. |
| `uri: https://developer.android.com/reference/android/net/Uri.html!` | The `https://developer.android.com/reference/android/net/Uri.html` of the media to extract from. |
| `headers: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>?` | 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/kotlin/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

```
fun setDataSource(fileDescriptor: FileDescriptor!, offset: Long, length: Long): Unit
```

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 |
|---|---|
| `fileDescriptor: https://developer.android.com/reference/java/io/FileDescriptor.html!` | The `https://developer.android.com/reference/java/io/FileDescriptor.html` for the file to extract from. |
| `offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The offset into the file where the data to be extracted starts, in bytes. |
| `length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The length of the data to be extracted, in bytes, or `https://developer.android.com/reference/kotlin/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/kotlin/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)
fun setLogSessionId(logSessionId: LogSessionId!): Unit
```

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

### unselectTrack

```
fun unselectTrack(trackIndex: Int): Unit
```

Unselects the track at the specified `trackIndex`.

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