FlacMetadataReader


@UnstableApi
public final class FlacMetadataReader


Reads and peeks FLAC stream metadata elements according to the FLAC format specification.

Summary

Nested types

Holds a FlacStreamMetadata.

Public methods

static boolean

Peeks the FLAC stream marker.

static int

Returns the frame start marker, consisting of the 2 first bytes of the first frame.

static @Nullable Metadata
peekId3Metadata(ExtractorInput input, boolean parseData)

Peeks ID3 Data.

static @Nullable Metadata
readId3Metadata(ExtractorInput input, boolean parseData)

Reads ID3 Data.

static boolean

Reads one FLAC metadata block.

static FlacStreamMetadata.SeekTable

Reads a FLAC seek table metadata block.

static void

Reads the FLAC stream marker.

Public methods

checkAndPeekStreamMarker

public static boolean checkAndPeekStreamMarker(ExtractorInput input)

Peeks the FLAC stream marker.

Parameters
ExtractorInput input

Input stream to peek the stream marker from.

Returns
boolean

Whether the data peeked is the FLAC stream marker.

Throws
java.io.IOException

If peeking from the input fails. In this case, the peek position is left unchanged.

getFrameStartMarker

public static int getFrameStartMarker(ExtractorInput input)

Returns the frame start marker, consisting of the 2 first bytes of the first frame.

The read position of input is left unchanged and the peek position is aligned with the read position.

Parameters
ExtractorInput input

Input stream to get the start marker from (starting from the read position).

Returns
int

The frame start marker (which must be the same for all the frames in the stream).

Throws
androidx.media3.common.ParserException

If an error occurs parsing the frame start marker.

java.io.IOException

If peeking from the input fails.

peekId3Metadata

public static @Nullable Metadata peekId3Metadata(ExtractorInput input, boolean parseData)

Peeks ID3 Data.

Parameters
ExtractorInput input

Input stream to peek the ID3 data from.

boolean parseData

Whether to parse the ID3 frames.

Returns
@Nullable Metadata

The parsed ID3 data, or null if there is no such data or if parseData is false.

Throws
java.io.IOException

If peeking from the input fails. In this case, there is no guarantee on the peek position.

readId3Metadata

public static @Nullable Metadata readId3Metadata(ExtractorInput input, boolean parseData)

Reads ID3 Data.

If no exception is thrown, the peek position of input is aligned with the read position.

Parameters
ExtractorInput input

Input stream to read the ID3 data from.

boolean parseData

Whether to parse the ID3 frames.

Returns
@Nullable Metadata

The parsed ID3 data, or null if there is no such data or if parseData is false.

Throws
java.io.IOException

If reading from the input fails. In this case, the read position is left unchanged and there is no guarantee on the peek position.

readMetadataBlock

public static boolean readMetadataBlock(
    ExtractorInput input,
    FlacMetadataReader.FlacStreamMetadataHolder metadataHolder
)

Reads one FLAC metadata block.

If no exception is thrown, the peek position of input is aligned with the read position.

Parameters
ExtractorInput input

Input stream to read the metadata block from (header included).

FlacMetadataReader.FlacStreamMetadataHolder metadataHolder

A holder for the metadata read. If the stream info block (which must be the first metadata block) is read, the holder contains a new instance representing the stream info data. If the block read is a Vorbis comment block or a picture block, the holder contains a copy of the existing stream metadata with the corresponding metadata added. Otherwise, the metadata in the holder is unchanged.

Returns
boolean

Whether the block read is the last metadata block.

Throws
java.lang.IllegalArgumentException

If the block read is not a stream info block and the metadata in metadataHolder is null. In this case, the read position will be at the start of a metadata block and there is no guarantee on the peek position.

java.io.IOException

If reading from the input fails. In this case, the read position will be at the start of a metadata block and there is no guarantee on the peek position.

readSeekTableMetadataBlock

public static FlacStreamMetadata.SeekTable readSeekTableMetadataBlock(ParsableByteArray data)

Reads a FLAC seek table metadata block.

The position of data is moved to the byte following the seek table metadata block (placeholder points included).

Parameters
ParsableByteArray data

The array to read the data from, whose position must correspond to the seek table metadata block (header included).

Returns
FlacStreamMetadata.SeekTable

The seek table, without the placeholder points.

readStreamMarker

public static void readStreamMarker(ExtractorInput input)

Reads the FLAC stream marker.

Parameters
ExtractorInput input

Input stream to read the stream marker from.

Throws
androidx.media3.common.ParserException

If an error occurs parsing the stream marker. In this case, the position of input is advanced by STREAM_MARKER_SIZE bytes.

java.io.IOException

If reading from the input fails. In this case, the position is left unchanged.