google/ExoPlayer · error · FlacDecoderException
Initialization data must be of length 1
Error message
Initialization data must be of length 1
What it means
FlacDecoderException thrown by the FlacDecoder constructor when the initializationData list does not contain exactly one entry. The FLAC extractor puts the raw STREAMINFO metadata block (the first metadata block of the file) into initializationData as its single element; any other size means the stream was not properly parsed as FLAC or the format was misdetected.
Source
Thrown at extensions/flac/src/main/java/com/google/android/exoplayer2/ext/flac/FlacDecoder.java:68
* Creates a Flac decoder.
*
* @param numInputBuffers The number of input buffers.
* @param numOutputBuffers The number of output buffers.
* @param maxInputBufferSize The maximum required input buffer size if known, or {@link
* Format#NO_VALUE} otherwise.
* @param initializationData Codec-specific initialization data. It should contain only one entry
* which is the flac file header.
* @throws FlacDecoderException Thrown if an exception occurs when initializing the decoder.
*/
public FlacDecoder(
int numInputBuffers,
int numOutputBuffers,
int maxInputBufferSize,
List<byte[]> initializationData)
throws FlacDecoderException {
super(new DecoderInputBuffer[numInputBuffers], new SimpleDecoderOutputBuffer[numOutputBuffers]);
if (initializationData.size() != 1) {
throw new FlacDecoderException("Initialization data must be of length 1");
}
decoderJni = new FlacDecoderJni();
decoderJni.setData(ByteBuffer.wrap(initializationData.get(0)));
try {
streamMetadata = decoderJni.decodeStreamMetadata();
} catch (ParserException e) {
throw new FlacDecoderException("Failed to decode StreamInfo", e);
} catch (IOException e) {
// Never happens.
throw new IllegalStateException(e);
}
int initialInputBufferSize =
maxInputBufferSize != Format.NO_VALUE ? maxInputBufferSize : streamMetadata.maxFrameSize;
setInitialInputBufferSize(initialInputBufferSize);
}
@OverrideView on GitHub (pinned to dd430f7053)
Solutions
- Ensure playback goes through the FlacExtractor (enable it via DefaultExtractorsFactory.setFlacExtractorArguments or the extension's extractor) so initializationData carries exactly the STREAMINFO block
- If you build the Format yourself, pass Collections.singletonList(streamInfoBytes) where the bytes are the 34-byte STREAMINFO block from the file header
- Verify the input actually is FLAC (check the 'fLaC' magic) before selecting the FLAC pipeline
- Catch FlacDecoderException during renderer init to fall back to platform FLAC decoding (API 27+) when available
Example fix
// before: hand-built Format with wrong init data shape
Format format = new Format.Builder()
.setSampleMimeType(MimeTypes.AUDIO_FLAC)
.setInitializationData(Collections.emptyList()) // size 0 -> throws
.build();
// after: single STREAMINFO entry from the file header
Format format = new Format.Builder()
.setSampleMimeType(MimeTypes.AUDIO_FLAC)
.setInitializationData(Collections.singletonList(streamInfoBlockBytes))
.build(); Defensive patterns
Strategy: validation
Validate before calling
boolean isFlacInitializationData(List<byte[]> init) {
if (init.size() != 1) return false;
byte[] block = init.get(0);
return block.length == 34; // FLAC STREAMINFO block payload size
}
if (!isFlacInitializationData(format.initializationData)) {
// refuse to construct FlacDecoder; select another FLAC pipeline or fail clearly
} Try / catch
try {
decoder = new FlacDecoder(numIn, numOut, maxIn, format.initializationData);
} catch (FlacDecoderException e) {
if (e.getMessage() != null && e.getMessage().contains("length 1")) {
// extractor produced wrong init data: re-extract with FlacExtractor and retry
format = reExtractWithFlacExtractor(inputUri);
decoder = new FlacDecoder(numIn, numOut, maxIn, format.initializationData);
} else {
throw e;
}
} Prevention
- Let the FLAC extension's own extractor produce the Format so initializationData always holds exactly the STREAMINFO block
- When constructing Format manually, always pass a single 34-byte stream-info entry
- Sniff for the 'fLaC' magic before routing files into the FLAC pipeline
When it happens
Trigger: Constructing FlacDecoder from a Format whose initializationData was produced by the wrong extractor (e.g. an ID3/other parser), was truncated, or was constructed manually with zero or multiple entries; feeding FLAC data through a generic pipeline that split or dropped the header block.
Common situations: Wrong extractor selected by DefaultExtractorsFactory for a file with a non-standard start; hand-built Format objects in tests or custom extractors; .flac files with junk prepended so sniffing picks another extractor.
Related errors
- Failed to decode StreamInfo
- Failed to initialize decoder. Error: ${gav1GetErrorMessage(g
- Initialization failed.
- Could not delete the previous export output file
- Could not create the export output file
AI-assisted analysis of google/ExoPlayer@dd430f7053 (2026-08-14).
Data as JSON: /api/errors/e5a31a246079c24f.
Report an issue: GitHub.