# MediaParserHlsMediaChunkExtractor

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/MediaParserHlsMediaChunkExtractor.java+class:androidx.media3.exoplayer.hls.MediaParserHlsMediaChunkExtractor)

*** ** * ** ***

<br />

```
@RequiresApi(value = 30)
@UnstableApi
public final class MediaParserHlsMediaChunkExtractor implements HlsMediaChunkExtractor
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/androidx/media3/exoplayer/hls/HlsMediaChunkExtractor` implemented on top of the platform's `https://developer.android.com/reference/android/media/MediaParser.html`.

## Summary

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/androidx/media3/exoplayer/hls/HlsExtractorFactory` | `https://developer.android.com/reference/androidx/media3/exoplayer/hls/MediaParserHlsMediaChunkExtractor#FACTORY()` `https://developer.android.com/reference/androidx/media3/exoplayer/hls/HlsExtractorFactory` implementation that produces `https://developer.android.com/reference/androidx/media3/exoplayer/hls/MediaParserHlsMediaChunkExtractor` for all container formats except WebVTT, for which a `https://developer.android.com/reference/androidx/media3/exoplayer/hls/BundledHlsMediaChunkExtractor` is returned. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/hls/MediaParserHlsMediaChunkExtractor#MediaParserHlsMediaChunkExtractor(android.media.MediaParser,androidx.media3.exoplayer.source.mediaparser.OutputConsumerAdapterV30,androidx.media3.common.Format,boolean,com.google.common.collect.ImmutableList<android.media.MediaFormat>,int,androidx.media3.exoplayer.analytics.PlayerId)( https://developer.android.com/reference/android/media/MediaParser.html mediaParser, https://developer.android.com/reference/androidx/media3/exoplayer/source/mediaparser/OutputConsumerAdapterV30 outputConsumerAdapter, https://developer.android.com/reference/androidx/media3/common/Format format, boolean overrideInBandCaptionDeclarations, https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/android/media/MediaFormat.html> muxedCaptionMediaFormats, int leadingBytesToSkip, https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId playerId )` Creates a new instance. |

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

## Constants

### FACTORY

```
public static final HlsExtractorFactory FACTORY
```

`https://developer.android.com/reference/androidx/media3/exoplayer/hls/HlsExtractorFactory` implementation that produces `https://developer.android.com/reference/androidx/media3/exoplayer/hls/MediaParserHlsMediaChunkExtractor` for all container formats except WebVTT, for which a `https://developer.android.com/reference/androidx/media3/exoplayer/hls/BundledHlsMediaChunkExtractor` is returned.

## Public constructors

### MediaParserHlsMediaChunkExtractor

```
public MediaParserHlsMediaChunkExtractor(
    MediaParser mediaParser,
    OutputConsumerAdapterV30 outputConsumerAdapter,
    Format format,
    boolean overrideInBandCaptionDeclarations,
    ImmutableList<MediaFormat> muxedCaptionMediaFormats,
    int leadingBytesToSkip,
    PlayerId playerId
)
```

Creates a new instance.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/media/MediaParser.html mediaParser` | The `https://developer.android.com/reference/android/media/MediaParser.html` instance to use for extraction of segments. The provided instance must have completed sniffing, or must have been created by name. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/mediaparser/OutputConsumerAdapterV30 outputConsumerAdapter` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/mediaparser/OutputConsumerAdapterV30` with which ` mediaParser` was created. |
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The `https://developer.android.com/reference/androidx/media3/common/Format` associated with the segment. |
| `boolean overrideInBandCaptionDeclarations` | Whether to ignore any in-band caption track declarations in favor of using the `muxedCaptionMediaFormats` instead. If false, caption declarations found in the extracted media will be used, causing ` muxedCaptionMediaFormats` to be ignored instead. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/android/media/MediaFormat.html> muxedCaptionMediaFormats` | The list of in-band caption `https://developer.android.com/reference/android/media/MediaFormat.html` that `https://developer.android.com/reference/android/media/MediaParser.html` should expose. |
| `int leadingBytesToSkip` | The number of bytes to skip from the start of the input before starting extraction. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId playerId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId` of the player using this chunk extractor. |

## Public methods

### init

```
public void init(ExtractorOutput extractorOutput)
```

Initializes the extractor with an `https://developer.android.com/reference/androidx/media3/extractor/ExtractorOutput`. Called at most once.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/ExtractorOutput extractorOutput` | An `https://developer.android.com/reference/androidx/media3/extractor/ExtractorOutput` to receive extracted data. |

### isPackedAudioExtractor

```
public boolean isPackedAudioExtractor()
```

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

### isReusable

```
public boolean isReusable()
```

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

### onTruncatedSegmentParsed

```
public void onTruncatedSegmentParsed()
```

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

```
public boolean read(ExtractorInput extractorInput)
```

Extracts data read from a provided `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput`. Must not be called before `https://developer.android.com/reference/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 `https://developer.android.com/reference/java/io/IOException.html`, extraction may continue by providing an `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` with an unchanged `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput#getPosition()` to a subsequent call to this method.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput extractorInput` | The input to read from. |

| Returns |
|---|---|
| `boolean` | Whether there is any data left to extract. Returns false if the end of input has been reached. |

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

### recreate

```
public HlsMediaChunkExtractor recreate()
```

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