PlayerEmsgHandler.PlayerTrackEmsgHandler


public final inner class PlayerEmsgHandler.PlayerTrackEmsgHandler implements TrackOutput


Handles emsg messages for a specific track for the player.

Summary

Public methods

void
format(Format format)

Called when the Format of the track has been extracted from the stream.

boolean
maybeRefreshManifestBeforeLoadingNextChunk(
    long presentationPositionUs
)

For live streaming, check if the DASH manifest is expired before the next segment start time.

void

Called when a chunk load has been completed.

boolean

Called when a chunk load has encountered an error.

void

Release this track emsg handler.

void
sampleData(
    ParsableByteArray data,
    int length,
    @TrackOutput.SampleDataPart int sampleDataPart
)

Called to write sample data to the output.

int
sampleData(
    DataReader input,
    int length,
    boolean allowEndOfInput,
    @TrackOutput.SampleDataPart int sampleDataPart
)

Called to write sample data to the output.

void
sampleMetadata(
    long timeUs,
    int flags,
    int size,
    int offset,
    @Nullable TrackOutput.CryptoData cryptoData
)

Called when metadata associated with a sample has been extracted from the stream.

Inherited Constants

From androidx.media3.extractor.TrackOutput
static final int

Sample encryption data.

static final int

Main media sample data.

static final int

Sample supplemental data.

Inherited methods

From androidx.media3.extractor.TrackOutput
void
sampleData(ParsableByteArray data, int length)

Equivalent to sampleData sampleData(data, length, SAMPLE_DATA_PART_MAIN)}.

int
sampleData(DataReader input, int length, boolean allowEndOfInput)

Equivalent to sampleData(input, length, allowEndOfInput, SAMPLE_DATA_PART_MAIN).

Public methods

format

public void format(Format format)

Called when the Format of the track has been extracted from the stream.

Parameters
Format format

The extracted Format.

maybeRefreshManifestBeforeLoadingNextChunk

public boolean maybeRefreshManifestBeforeLoadingNextChunk(
    long presentationPositionUs
)

For live streaming, check if the DASH manifest is expired before the next segment start time. If it is, the DASH media source will be notified to refresh the manifest.

Parameters
long presentationPositionUs

The next load position in presentation time.

Returns
boolean

True if manifest refresh has been requested, false otherwise.

onChunkLoadCompleted

public void onChunkLoadCompleted(Chunk chunk)

Called when a chunk load has been completed.

Parameters
Chunk chunk

The chunk whose load has been completed.

onChunkLoadError

public boolean onChunkLoadError(Chunk chunk)

Called when a chunk load has encountered an error.

Parameters
Chunk chunk

The chunk whose load encountered an error.

Returns
boolean

Whether a manifest refresh has been requested.

release

public void release()

Release this track emsg handler. It should not be reused after this call.

sampleData

public void sampleData(
    ParsableByteArray data,
    int length,
    @TrackOutput.SampleDataPart int sampleDataPart
)

Called to write sample data to the output.

Parameters
ParsableByteArray data

A ParsableByteArray from which to read the sample data.

int length

The number of bytes to read, starting from data.getPosition().

@TrackOutput.SampleDataPart int sampleDataPart

The part of the sample data to which this call corresponds.

sampleData

public int sampleData(
    DataReader input,
    int length,
    boolean allowEndOfInput,
    @TrackOutput.SampleDataPart int sampleDataPart
)

Called to write sample data to the output.

Parameters
DataReader input

A DataReader from which to read the sample data.

int length

The maximum length to read from the input.

boolean allowEndOfInput

True if encountering the end of the input having read no data is allowed, and should result in RESULT_END_OF_INPUT being returned. False if it should be considered an error, causing an EOFException to be thrown.

@TrackOutput.SampleDataPart int sampleDataPart

The part of the sample data to which this call corresponds.

Returns
int

The number of bytes appended.

Throws
java.io.IOException

If an error occurred reading from the input.

sampleMetadata

public void sampleMetadata(
    long timeUs,
    int flags,
    int size,
    int offset,
    @Nullable TrackOutput.CryptoData cryptoData
)

Called when metadata associated with a sample has been extracted from the stream.

The corresponding sample data will have already been passed to the output via calls to sampleData or sampleData.

Parameters
long timeUs

The media timestamp associated with the sample, in microseconds.

int flags

Flags associated with the sample. See C.BUFFER_FLAG_*.

int size

The size of the sample data, in bytes.

int offset

The number of bytes that have been passed to sampleData or sampleData since the last byte belonging to the sample whose metadata is being passed.

@Nullable TrackOutput.CryptoData cryptoData

The encryption data required to decrypt the sample. May be null.