# HlsMediaChunkExtractor

# HlsMediaChunkExtractor

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

*** ** * ** ***

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


```
@UnstableApi
interface HlsMediaChunkExtractor
```

<br />

Known direct subclasses  
[BundledHlsMediaChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/BundledHlsMediaChunkExtractor), [MediaParserHlsMediaChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/MediaParserHlsMediaChunkExtractor)  

|-----------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [BundledHlsMediaChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/BundledHlsMediaChunkExtractor)         | [HlsMediaChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaChunkExtractor) implementation that uses ExoPlayer app-bundled [Extractors](https://developer.android.com/reference/kotlin/androidx/media3/extractor/Extractor). |
| [MediaParserHlsMediaChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/MediaParserHlsMediaChunkExtractor) | [HlsMediaChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaChunkExtractor) 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 [HlsMediaChunks](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaChunk).

## Summary

|                                                       ### Public functions                                                       |
|----------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                    | [init](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaChunkExtractor#init(androidx.media3.extractor.ExtractorOutput))`(extractorOutput: `[ExtractorOutput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorOutput)`!)` Initializes the extractor with an [ExtractorOutput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorOutput). |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                              | [isPackedAudioExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaChunkExtractor#isPackedAudioExtractor())`()` Returns whether this is a packed audio extractor, as defined in RFC 8216, Section 3.4.                                                                                                                                                                                             |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                              | [isReusable](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaChunkExtractor#isReusable())`()` Returns whether this instance can be used for extracting multiple continuous segments.                                                                                                                                                                                                                     |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                    | [onTruncatedSegmentParsed](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaChunkExtractor#onTruncatedSegmentParsed())`()` Resets the sample parsing state.                                                                                                                                                                                                                                               |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                              | [read](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaChunkExtractor#read(androidx.media3.extractor.ExtractorInput))`(extractorInput: `[ExtractorInput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput)`!)` Extracts data read from a provided [ExtractorInput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput).      |
| [HlsMediaChunkExtractor](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaChunkExtractor)`!` | [recreate](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaChunkExtractor#recreate())`()` Returns a new instance for extracting the same type of media as this one.                                                                                                                                                                                                                                      |

## Public functions

### init

```
fun init(extractorOutput: ExtractorOutput!): Unit
```

Initializes the extractor with an [ExtractorOutput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorOutput). Called at most once.  

|                                                            Parameters                                                             |
|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| `extractorOutput: `[ExtractorOutput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorOutput)`!` | An [ExtractorOutput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorOutput) to receive extracted data. |

### isPackedAudioExtractor

```
fun isPackedAudioExtractor(): Boolean
```

Returns whether this is a packed audio extractor, as defined in RFC 8216, Section 3.4.  

### isReusable

```
fun isReusable(): Boolean
```

Returns whether this instance can be used for extracting multiple continuous segments.  

### onTruncatedSegmentParsed

```
fun onTruncatedSegmentParsed(): Unit
```

Resets the sample parsing state.

Resetting the parsing state allows support for Fragmented MP4 EXT-X-I-FRAME-STREAM-INF segments. EXT-X-I-FRAME-STREAM-INF segments are truncated to include only a leading key frame. After parsing said keyframe, an extractor may reach an unexpected end of file. By resetting its state, we can continue feeding samples from the following segments to the extractor. See [#7512](https://github.com/google/ExoPlayer/issues/7512) for context.  

### read

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

Extracts data read from a provided [ExtractorInput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput). Must not be called before [init](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaChunkExtractor#init(androidx.media3.extractor.ExtractorOutput)).

A single call to this method will block until some progress has been made, but will not block for longer than this. Hence each call will consume only a small amount of input data.

When this method throws an [IOException](https://developer.android.com/reference/java/io/IOException.html), extraction may continue by providing an [ExtractorInput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput) with an unchanged [read position](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput#getPosition()) to a subsequent call to this method.  

|                                                           Parameters                                                           |
|--------------------------------------------------------------------------------------------------------------------------------|-------------------------|
| `extractorInput: `[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. |

### recreate

```
fun recreate(): HlsMediaChunkExtractor!
```

Returns a new instance for extracting the same type of media as this one. Can only be called on instances that are not [reusable](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaChunkExtractor#isReusable()).