Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

# MediaParser.OutputConsumer

*** ** * ** ***

` public static interface MediaParser.OutputConsumer `   
` `

|---|
| android.media.MediaParser.OutputConsumer |

<br />

*** ** * ** ***

Receives extracted media sample data and metadata from `https://developer.android.com/reference/android/media/MediaParser`.

## Summary

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/android/media/MediaParser.OutputConsumer#onSampleCompleted(int,%20long,%20int,%20int,%20int,%20android.media.MediaCodec.CryptoInfo)(int trackIndex, long timeMicros, int flags, int size, int offset, https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo cryptoInfo) ` Called once all the data of a sample has been passed to `https://developer.android.com/reference/android/media/MediaParser.OutputConsumer#onSampleDataFound(int,%20android.media.MediaParser.InputReader)`. |
| ` abstract void` | ` https://developer.android.com/reference/android/media/MediaParser.OutputConsumer#onSampleDataFound(int,%20android.media.MediaParser.InputReader)(int trackIndex, https://developer.android.com/reference/android/media/MediaParser.InputReader inputReader) ` Called when sample data is found in the stream. |
| ` abstract void` | ` https://developer.android.com/reference/android/media/MediaParser.OutputConsumer#onSeekMapFound(android.media.MediaParser.SeekMap)(https://developer.android.com/reference/android/media/MediaParser.SeekMap seekMap) ` Called when a `https://developer.android.com/reference/android/media/MediaParser.SeekMap` has been extracted from the stream. |
| ` abstract void` | ` https://developer.android.com/reference/android/media/MediaParser.OutputConsumer#onTrackCountFound(int)(int numberOfTracks) ` Called when the number of tracks is found. |
| ` abstract void` | ` https://developer.android.com/reference/android/media/MediaParser.OutputConsumer#onTrackDataFound(int,%20android.media.MediaParser.TrackData)(int trackIndex, https://developer.android.com/reference/android/media/MediaParser.TrackData trackData) ` Called when new `https://developer.android.com/reference/android/media/MediaParser.TrackData` is found in the stream. |

## Public methods

### onSampleCompleted

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onSampleCompleted (int trackIndex, 
                long timeMicros, 
                int flags, 
                int size, 
                int offset, 
                MediaCodec.CryptoInfo cryptoInfo)
```

Called once all the data of a sample has been passed to `https://developer.android.com/reference/android/media/MediaParser.OutputConsumer#onSampleDataFound(int,%20android.media.MediaParser.InputReader)`.

Includes sample metadata, like presentation timestamp and flags.

<br />

| Parameters ||
|---|---|
| `trackIndex` | `int`: The index of the track to which the sample corresponds. <br /> |
| `timeMicros` | `long`: The media timestamp associated with the sample, in microseconds. <br /> |
| `flags` | `int`: Flags associated with the sample. See the `SAMPLE_FLAG_*` constants. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/media/MediaParser#SAMPLE_FLAG_KEY_FRAME` - `https://developer.android.com/reference/android/media/MediaParser#SAMPLE_FLAG_HAS_SUPPLEMENTAL_DATA` - `https://developer.android.com/reference/android/media/MediaParser#SAMPLE_FLAG_LAST_SAMPLE` - `https://developer.android.com/reference/android/media/MediaParser#SAMPLE_FLAG_ENCRYPTED` - `https://developer.android.com/reference/android/media/MediaParser#SAMPLE_FLAG_DECODE_ONLY` |
| `size` | `int`: The size of the sample data, in bytes. <br /> |
| `offset` | `int`: The number of bytes that have been consumed by `onSampleDataFound(int, MediaParser.InputReader)` for the specified track, since the last byte belonging to the sample whose metadata is being passed. <br /> |
| `cryptoInfo` | `MediaCodec.CryptoInfo`: Encryption data required to decrypt the sample. May be null for unencrypted samples. Implementors should treat any output `https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo` instances as immutable. MediaParser will not modify any output `cryptoInfos` and implementors should not modify them either. <br /> |

### onSampleDataFound

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onSampleDataFound (int trackIndex, 
                MediaParser.InputReader inputReader)
```

Called when sample data is found in the stream.

If the invocation of this method returns before the entire `inputReader` `https://developer.android.com/reference/android/media/MediaParser.InputReader#getLength()` is consumed, the method will be called again for the implementer to read the remaining data. Implementers should surface any thrown `https://developer.android.com/reference/java/io/IOException` caused by reading from `input`.

<br />

| Parameters ||
|---|---|
| `trackIndex` | `int`: The index of the track to which the sample data corresponds. <br /> |
| `inputReader` | `MediaParser.InputReader`: The `https://developer.android.com/reference/android/media/MediaParser.InputReader` from which to read the data. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an exception occurs while reading from `inputReader`. |

### onSeekMapFound

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onSeekMapFound (MediaParser.SeekMap seekMap)
```

Called when a `https://developer.android.com/reference/android/media/MediaParser.SeekMap` has been extracted from the stream.

This method is called at least once before any samples are `https://developer.android.com/reference/android/media/MediaParser.OutputConsumer#onSampleCompleted(int,%20long,%20int,%20int,%20int,%20android.media.MediaCodec.CryptoInfo)`. May be called multiple times after that in order to add `https://developer.android.com/reference/android/media/MediaParser.SeekPoint`.

<br />

| Parameters ||
|---|---|
| `seekMap` | `MediaParser.SeekMap`: The extracted `https://developer.android.com/reference/android/media/MediaParser.SeekMap`. This value cannot be `null`. <br /> |

### onTrackCountFound

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onTrackCountFound (int numberOfTracks)
```

Called when the number of tracks is found.

<br />

| Parameters ||
|---|---|
| `numberOfTracks` | `int`: The number of tracks in the stream. <br /> |

### onTrackDataFound

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onTrackDataFound (int trackIndex, 
                MediaParser.TrackData trackData)
```

Called when new `https://developer.android.com/reference/android/media/MediaParser.TrackData` is found in the stream.

<br />

| Parameters ||
|---|---|
| `trackIndex` | `int`: The index of the track for which the `https://developer.android.com/reference/android/media/MediaParser.TrackData` was extracted. <br /> |
| `trackData` | `MediaParser.TrackData`: The extracted `https://developer.android.com/reference/android/media/MediaParser.TrackData`. This value cannot be `null`. <br /> |