{"record":{"id":"d031c77fcdb6b388","repo":"google/ExoPlayer","slug":"unhandled-input-format-audioformat-d031c7","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/SonicAudioProcessor.java","lineNumber":154,"sourceCode":"    if (outputBytes >= MIN_BYTES_FOR_DURATION_SCALING_CALCULATION) {\n      long processedInputBytes = inputBytes - checkNotNull(sonic).getPendingInputBytes();\n      return outputAudioFormat.sampleRate == inputAudioFormat.sampleRate\n          ? Util.scaleLargeTimestamp(playoutDuration, processedInputBytes, outputBytes)\n          : Util.scaleLargeTimestamp(\n              playoutDuration,\n              processedInputBytes * outputAudioFormat.sampleRate,\n              outputBytes * inputAudioFormat.sampleRate);\n    } else {\n      return (long) ((double) speed * playoutDuration);\n    }\n  }\n\n  @Override\n  @CanIgnoreReturnValue\n  public final AudioFormat configure(AudioFormat inputAudioFormat)\n      throws UnhandledAudioFormatException {\n    if (inputAudioFormat.encoding != C.ENCODING_PCM_16BIT) {\n      throw new UnhandledAudioFormatException(inputAudioFormat);\n    }\n    int outputSampleRateHz =\n        pendingOutputSampleRate == SAMPLE_RATE_NO_CHANGE\n            ? inputAudioFormat.sampleRate\n            : pendingOutputSampleRate;\n    pendingInputAudioFormat = inputAudioFormat;\n    pendingOutputAudioFormat =\n        new AudioFormat(outputSampleRateHz, inputAudioFormat.channelCount, C.ENCODING_PCM_16BIT);\n    pendingSonicRecreation = true;\n    return pendingOutputAudioFormat;\n  }\n\n  @Override\n  public final boolean isActive() {\n    return pendingOutputAudioFormat.sampleRate != Format.NO_VALUE\n        && (Math.abs(speed - 1f) >= CLOSE_THRESHOLD\n            || Math.abs(pitch - 1f) >= CLOSE_THRESHOLD\n            || pendingOutputAudioFormat.sampleRate != pendingInputAudioFormat.sampleRate);","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/google/ExoPlayer/blob/dd430f7053a1a3958deea3ead6a0565150c06bfc/library/common/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java#L136-L172","documentation":"SonicAudioProcessor — the speed/pitch/time-stretch processor used by PlaybackParameters — only accepts C.ENCODING_PCM_16BIT input. Its configure() throws AudioProcessor.UnhandledAudioFormatException for any other encoding before any stretching happens. This commonly surfaces as a crash when setPlaybackParameters is used with sources that decode to float or 24-bit PCM.","triggerScenarios":"Calling sonicAudioProcessor.configure(format) (directly or through the default audio sink chain when playback speed != 1x) with encoding != ENCODING_PCM_16BIT, e.g. ENCODING_PCM_FLOAT from a decoder with float output enabled.","commonSituations":"Calling setPlaybackSpeed(1.5f) while DefaultRenderersFactory was built with setEnableDecoderFloatOutput(true); playing high-bitrate FLAC that decodes to 24-bit PCM and then changing speed; OEM audio pipelines that negotiate non-16-bit PCM output.","solutions":["Ensure the sink/decoder chain delivers 16-bit PCM when speed adjustment is active: disable float decoder output (setEnableDecoderFloatOutput(false)) or insert ToInt16PcmAudioProcessor before Sonic.","If you construct the processor chain manually, order it ToInt16PcmAudioProcessor -> SonicAudioProcessor.","Catch UnhandledAudioFormatException to disable speed processing for unsupported encodings rather than fail playback."],"exampleFix":"// before\nDefaultRenderersFactory factory = new DefaultRenderersFactory(context)\n    .setEnableDecoderFloatOutput(true);\nplayer.setPlaybackSpeed(1.5f); // Sonic.configure(PCM_FLOAT) -> throws\n\n// after\nDefaultRenderersFactory factory = new DefaultRenderersFactory(context)\n    .setEnableDecoderFloatOutput(false);\nplayer.setPlaybackSpeed(1.5f); // OK: Sonic receives PCM 16BIT","handlingStrategy":"validation","validationCode":"if (format.encoding == C.ENCODING_PCM_16BIT) {\n  sonicProcessor.configure(format);\n} else {\n  AudioFormat pcm16 = toInt16Processor.configure(format);\n  sonicProcessor.configure(pcm16);\n}","typeGuard":null,"tryCatchPattern":"try {\n  sonic.configure(inputFormat);\n} catch (AudioProcessor.UnhandledAudioFormatException e) {\n  // Speed adjustment unavailable for this encoding; reset to 1x or bypass Sonic\n  playbackParameters = new PlaybackParameters(1f);\n}","preventionTips":["Keep decoder float output disabled when speed/pitch processing is needed.","Insert ToInt16PcmAudioProcessor before SonicAudioProcessor in custom chains.","Pre-check format.encoding == C.ENCODING_PCM_16BIT before enabling playback-parameters UI."],"tags":["exoplayer","media3","audio","sonic","playback-speed","pcm"],"backgroundTag":null,"analyzedSha":"dd430f7053a1a3958deea3ead6a0565150c06bfc","analyzedAt":"2026-08-14T12:22:02.982Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}