{"record":{"id":"191fbb72e6965352","repo":"google/ExoPlayer","slug":"unhandled-input-format-audioformat-191fbb","errorCode":null,"errorMessage":"Unhandled input format: {audioFormat}","messagePattern":"Unhandled input format: (.+?)","errorType":"exception","errorClass":"UnhandledAudioFormatException","httpStatus":null,"severity":"error","filePath":"library/common/src/main/java/com/google/android/exoplayer2/audio/ToInt16PcmAudioProcessor.java","lineNumber":56,"sourceCode":" *     contains the same ExoPlayer code). See <a\n *     href=\"https://developer.android.com/guide/topics/media/media3/getting-started/migration-guide\">the\n *     migration guide</a> for more details, including a script to help with the migration.\n */\n@Deprecated\npublic final class ToInt16PcmAudioProcessor extends BaseAudioProcessor {\n\n  @Override\n  @CanIgnoreReturnValue\n  public AudioFormat onConfigure(AudioFormat inputAudioFormat)\n      throws UnhandledAudioFormatException {\n    @C.PcmEncoding int encoding = inputAudioFormat.encoding;\n    if (encoding != C.ENCODING_PCM_8BIT\n        && encoding != C.ENCODING_PCM_16BIT\n        && encoding != C.ENCODING_PCM_16BIT_BIG_ENDIAN\n        && encoding != C.ENCODING_PCM_24BIT\n        && encoding != C.ENCODING_PCM_32BIT\n        && encoding != C.ENCODING_PCM_FLOAT) {\n      throw new UnhandledAudioFormatException(inputAudioFormat);\n    }\n    return encoding != C.ENCODING_PCM_16BIT\n        ? new AudioFormat(\n            inputAudioFormat.sampleRate, inputAudioFormat.channelCount, C.ENCODING_PCM_16BIT)\n        : AudioFormat.NOT_SET;\n  }\n\n  @Override\n  public void queueInput(ByteBuffer inputBuffer) {\n    // Prepare the output buffer.\n    int position = inputBuffer.position();\n    int limit = inputBuffer.limit();\n    int size = limit - position;\n    int resampledSize;\n    switch (inputAudioFormat.encoding) {\n      case C.ENCODING_PCM_8BIT:\n        resampledSize = size * 2;\n        break;","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/google/ExoPlayer/blob/dd430f7053a1a3958deea3ead6a0565150c06bfc/library/common/src/main/java/com/google/android/exoplayer2/audio/ToInt16PcmAudioProcessor.java#L38-L74","documentation":"ToInt16PcmAudioProcessor converts any integer or float PCM encoding to 16-bit PCM. onConfigure throws AudioProcessor.UnhandledAudioFormatException when the encoding is not one of the accepted PCM encodings: 8-bit, 16-bit (little and big endian), 24-bit, 32-bit integer, or float. Compressed or passthrough encodings (e.g. ENCODING_AC3, ENCODING_E_AC3) and any unknown constant are rejected.","triggerScenarios":"Calling toInt16PcmAudioProcessor.configure(format) with a compressed/passthrough encoding such as ENCODING_AC3 or ENCODING_DTS, or any non-PCM C.PcmEncoding constant — typically when the audio path negotiates an offload/passthrough format.","commonSituations":"Static processor chains applied unconditionally to all tracks, including Dolby passthrough on TVs/soundbars; audio offload playback where the sink receives compressed data; enumerating a device's supported encodings and feeding one straight into the processor.","solutions":["Only attach ToInt16PcmAudioProcessor when the track's sample encoding is a known PCM type; bypass the conversion chain for passthrough/compressed formats.","Gate on Format.sampleEncoding (or C.ENCODING_*) before building the processor chain: check Util.isEncodingLinearPcm-compatible PCM encodings list.","Catch UnhandledAudioFormatException to fall back to direct playback without conversion."],"exampleFix":"// before\nToInt16PcmAudioProcessor conv = new ToInt16PcmAudioProcessor();\nconv.configure(new AudioFormat(48000, 6, C.ENCODING_AC3)); // throws\n\n// after\n@C.PcmEncoding int enc = format.sampleEncoding;\nboolean isPcm = enc == C.ENCODING_PCM_8BIT || enc == C.ENCODING_PCM_16BIT\n    || enc == C.ENCODING_PCM_16BIT_BIG_ENDIAN || enc == C.ENCODING_PCM_24BIT\n    || enc == C.ENCODING_PCM_32BIT || enc == C.ENCODING_PCM_FLOAT;\nif (isPcm) {\n  conv.configure(new AudioFormat(format.sampleRate, format.channelCount, enc));\n} else {\n  // passthrough path without PCM conversion\n}","handlingStrategy":"type-guard","validationCode":"private static final Set<Integer> ACCEPTED = Set.of(\n    C.ENCODING_PCM_8BIT, C.ENCODING_PCM_16BIT, C.ENCODING_PCM_16BIT_BIG_ENDIAN,\n    C.ENCODING_PCM_24BIT, C.ENCODING_PCM_32BIT, C.ENCODING_PCM_FLOAT);\nif (ACCEPTED.contains(format.encoding)) {\n  toInt16Processor.configure(format);\n} else {\n  // compressed / passthrough: skip PCM conversion chain\n}","typeGuard":"public static boolean isConvertiblePcm(@C.PcmEncoding int encoding) {\n  return encoding == C.ENCODING_PCM_8BIT\n      || encoding == C.ENCODING_PCM_16BIT\n      || encoding == C.ENCODING_PCM_16BIT_BIG_ENDIAN\n      || encoding == C.ENCODING_PCM_24BIT\n      || encoding == C.ENCODING_PCM_32BIT\n      || encoding == C.ENCODING_PCM_FLOAT;\n}","tryCatchPattern":"try {\n  processor.configure(format);\n} catch (AudioProcessor.UnhandledAudioFormatException e) {\n  // Fall back to direct playback without PCM conversion\n  usePassthroughPath(format);\n}","preventionTips":["Never feed compressed/passthrough encodings (AC3, DTS, SBC, AACLH...) into PCM processors.","Branch your processor chain on the track format before playback starts, not after configure throws.","Remember ENCODING_PCM_16BIT returns AudioFormat.NOT_SET from onConfigure — the processor is inactive by design, not an error."],"tags":["exoplayer","media3","audio","pcm","passthrough","audio-processor"],"backgroundTag":null,"analyzedSha":"dd430f7053a1a3958deea3ead6a0565150c06bfc","analyzedAt":"2026-08-14T12:22:02.982Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}