Added in API level 30

OutputConsumer

interface OutputConsumer
android.media.MediaParser.OutputConsumer

Receives extracted media sample data and metadata from MediaParser.

Summary

Public methods
abstract Unit
onSampleCompleted(trackIndex: Int, timeMicros: Long, flags: Int, size: Int, offset: Int, cryptoInfo: MediaCodec.CryptoInfo?)

Called once all the data of a sample has been passed to onSampleDataFound.

abstract Unit
onSampleDataFound(trackIndex: Int, inputReader: MediaParser.InputReader)

Called when sample data is found in the stream.

abstract Unit

Called when a SeekMap has been extracted from the stream.

abstract Unit
onTrackCountFound(numberOfTracks: Int)

Called when the number of tracks is found.

abstract Unit
onTrackDataFound(trackIndex: Int, trackData: MediaParser.TrackData)

Called when new TrackData is found in the stream.

Public methods

onSampleCompleted

Added in API level 30
abstract fun onSampleCompleted(
    trackIndex: Int,
    timeMicros: Long,
    flags: Int,
    size: Int,
    offset: Int,
    cryptoInfo: MediaCodec.CryptoInfo?
): Unit

Called once all the data of a sample has been passed to onSampleDataFound.

Includes sample metadata, like presentation timestamp and flags.

Parameters
trackIndex Int: The index of the track to which the sample corresponds.
timeMicros Long: The media timestamp associated with the sample, in microseconds.
flags Int: Flags associated with the sample. See the SAMPLE_FLAG_* constants. Value is either 0 or a combination of android.media.MediaParser#SAMPLE_FLAG_KEY_FRAME, android.media.MediaParser#SAMPLE_FLAG_HAS_SUPPLEMENTAL_DATA, android.media.MediaParser#SAMPLE_FLAG_LAST_SAMPLE, android.media.MediaParser#SAMPLE_FLAG_ENCRYPTED, and android.media.MediaParser#SAMPLE_FLAG_DECODE_ONLY
size Int: The size of the sample data, in bytes.
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.
cryptoInfo MediaCodec.CryptoInfo?: Encryption data required to decrypt the sample. May be null for unencrypted samples. Implementors should treat any output CryptoInfo instances as immutable. MediaParser will not modify any output cryptoInfos and implementors should not modify them either.

onSampleDataFound

Added in API level 30
abstract fun onSampleDataFound(
    trackIndex: Int,
    inputReader: MediaParser.InputReader
): Unit

Called when sample data is found in the stream.

If the invocation of this method returns before the entire inputReader length is consumed, the method will be called again for the implementer to read the remaining data. Implementers should surface any thrown IOException caused by reading from input.

Parameters
trackIndex Int: The index of the track to which the sample data corresponds.
inputReader MediaParser.InputReader: The InputReader from which to read the data. This value cannot be null.
Exceptions
java.io.IOException If an exception occurs while reading from inputReader.

onSeekMapFound

Added in API level 30
abstract fun onSeekMapFound(seekMap: MediaParser.SeekMap): Unit

Called when a SeekMap has been extracted from the stream.

This method is called at least once before any samples are complete. May be called multiple times after that in order to add SeekPoints.

Parameters
seekMap MediaParser.SeekMap: The extracted SeekMap. This value cannot be null.

onTrackCountFound

Added in API level 30
abstract fun onTrackCountFound(numberOfTracks: Int): Unit

Called when the number of tracks is found.

Parameters
numberOfTracks Int: The number of tracks in the stream.

onTrackDataFound

Added in API level 30
abstract fun onTrackDataFound(
    trackIndex: Int,
    trackData: MediaParser.TrackData
): Unit

Called when new TrackData is found in the stream.

Parameters
trackIndex Int: The index of the track for which the TrackData was extracted.
trackData MediaParser.TrackData: The extracted TrackData. This value cannot be null.