# ChunkExtractor

# ChunkExtractor

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkExtractor "View this page in Java")

<br />

```
@UnstableApi
interface ChunkExtractor
```

<br />

Known direct subclasses  
[BundledChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/BundledChunkExtractor),[MediaParserChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaParserChunkExtractor)  

|----------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [BundledChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/BundledChunkExtractor)         | [ChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor)implementation that uses ExoPlayer app-bundled[Extractors](https://developer.android.com/reference/kotlin/androidx/media3/extractor/Extractor). |
| [MediaParserChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaParserChunkExtractor) | [ChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor)implemented on top of the platform's[MediaParser](https://developer.android.com/reference/android/media/MediaParser.html).                      |

*** ** * ** ***

Extracts samples and track[Formats](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)from chunks.

The[TrackOutputProvider](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor.TrackOutputProvider)passed to[init](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor#init(androidx.media3.exoplayer.source.chunk.ChunkExtractor.TrackOutputProvider,long,long))provides the[TrackOutputs](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput)that receive the extracted data.

## Summary

|                                                                                                                                                          ### Nested types                                                                                                                                                           |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `interface `[ChunkExtractor.Factory](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor.Factory) Creates[ChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor)instances.                                          |
| `interface `[ChunkExtractor.TrackOutputProvider](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor.TrackOutputProvider) Provides[TrackOutput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput)instances to be written to during extraction. |

|                                                                             ### Public functions                                                                              |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ChunkIndex](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex)`?`                                                                          | [getChunkIndex](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor#getChunkIndex())`()` Returns the[ChunkIndex](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex)most recently obtained from the chunks, or null if a[ChunkIndex](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex)has not been obtained.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!>?` | [getSampleFormats](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor#getSampleFormats())`()` Returns the sample[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)s for the tracks identified by the extractor, or null if the extractor has not finished identifying tracks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                 | [init](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor#init(androidx.media3.exoplayer.source.chunk.ChunkExtractor.TrackOutputProvider,long,long))`(` ` trackOutputProvider: `[ChunkExtractor.TrackOutputProvider](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor.TrackOutputProvider)`?,` ` startTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` endTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) `)` Initializes the wrapper to output to[TrackOutput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput)s provided by the specified[TrackOutputProvider](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor.TrackOutputProvider), and configures the extractor to receive data from a new chunk. |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                           | [read](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor#read(androidx.media3.extractor.ExtractorInput))`(input: `[ExtractorInput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput)`!)` Reads from the given[ExtractorInput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                 | [release](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor#release())`()` Releases any held resources.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

## Public functions

### getChunkIndex

```
fun getChunkIndex(): ChunkIndex?
```

Returns the[ChunkIndex](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex)most recently obtained from the chunks, or null if a[ChunkIndex](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex)has not been obtained.  

### getSampleFormats

```
fun getSampleFormats(): Array<Format!>?
```

Returns the sample[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)s for the tracks identified by the extractor, or null if the extractor has not finished identifying tracks.  

### init

```
fun init(
    trackOutputProvider: ChunkExtractor.TrackOutputProvider?,
    startTimeUs: Long,
    endTimeUs: Long
): Unit
```

Initializes the wrapper to output to[TrackOutput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput)s provided by the specified[TrackOutputProvider](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor.TrackOutputProvider), and configures the extractor to receive data from a new chunk.  

|                                                                                        Parameters                                                                                        |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `trackOutputProvider: `[ChunkExtractor.TrackOutputProvider](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor.TrackOutputProvider)`?` | The provider of[TrackOutput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput)s that will receive sample data.                                      |
| `startTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                                                             | The start position in the new chunk, or[TIME_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#TIME_UNSET())to output samples from the start of the chunk. |
| `endTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                                                               | The end position in the new chunk, or[TIME_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#TIME_UNSET())to output samples to the end of the chunk.       |

### read

```
fun read(input: ExtractorInput!): Boolean
```

Reads from the given[ExtractorInput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput).  

|                                                      Parameters                                                       |
|-----------------------------------------------------------------------------------------------------------------------|-------------------------|
| `input: `[ExtractorInput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput)`!` | The input to read from. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether there is any data left to extract. Returns false if the end of input has been reached. |

|                                         Throws                                          |
|-----------------------------------------------------------------------------------------|---------------------------------------------------------|
| [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) | If an error occurred reading from or parsing the input. |

### release

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

Releases any held resources.