google/ExoPlayer · error · UnhandledAudioFormatException

Unhandled input format: {audioFormat}

Error message

Unhandled input format: {audioFormat}

What it means

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.

Source

Thrown at library/common/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java:154

    if (outputBytes >= MIN_BYTES_FOR_DURATION_SCALING_CALCULATION) {
      long processedInputBytes = inputBytes - checkNotNull(sonic).getPendingInputBytes();
      return outputAudioFormat.sampleRate == inputAudioFormat.sampleRate
          ? Util.scaleLargeTimestamp(playoutDuration, processedInputBytes, outputBytes)
          : Util.scaleLargeTimestamp(
              playoutDuration,
              processedInputBytes * outputAudioFormat.sampleRate,
              outputBytes * inputAudioFormat.sampleRate);
    } else {
      return (long) ((double) speed * playoutDuration);
    }
  }

  @Override
  @CanIgnoreReturnValue
  public final AudioFormat configure(AudioFormat inputAudioFormat)
      throws UnhandledAudioFormatException {
    if (inputAudioFormat.encoding != C.ENCODING_PCM_16BIT) {
      throw new UnhandledAudioFormatException(inputAudioFormat);
    }
    int outputSampleRateHz =
        pendingOutputSampleRate == SAMPLE_RATE_NO_CHANGE
            ? inputAudioFormat.sampleRate
            : pendingOutputSampleRate;
    pendingInputAudioFormat = inputAudioFormat;
    pendingOutputAudioFormat =
        new AudioFormat(outputSampleRateHz, inputAudioFormat.channelCount, C.ENCODING_PCM_16BIT);
    pendingSonicRecreation = true;
    return pendingOutputAudioFormat;
  }

  @Override
  public final boolean isActive() {
    return pendingOutputAudioFormat.sampleRate != Format.NO_VALUE
        && (Math.abs(speed - 1f) >= CLOSE_THRESHOLD
            || Math.abs(pitch - 1f) >= CLOSE_THRESHOLD
            || pendingOutputAudioFormat.sampleRate != pendingInputAudioFormat.sampleRate);

View on GitHub (pinned to dd430f7053)

Solutions

  1. 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.
  2. If you construct the processor chain manually, order it ToInt16PcmAudioProcessor -> SonicAudioProcessor.
  3. Catch UnhandledAudioFormatException to disable speed processing for unsupported encodings rather than fail playback.

Example fix

// before
DefaultRenderersFactory factory = new DefaultRenderersFactory(context)
    .setEnableDecoderFloatOutput(true);
player.setPlaybackSpeed(1.5f); // Sonic.configure(PCM_FLOAT) -> throws

// after
DefaultRenderersFactory factory = new DefaultRenderersFactory(context)
    .setEnableDecoderFloatOutput(false);
player.setPlaybackSpeed(1.5f); // OK: Sonic receives PCM 16BIT
Defensive patterns

Strategy: validation

Validate before calling

if (format.encoding == C.ENCODING_PCM_16BIT) {
  sonicProcessor.configure(format);
} else {
  AudioFormat pcm16 = toInt16Processor.configure(format);
  sonicProcessor.configure(pcm16);
}

Try / catch

try {
  sonic.configure(inputFormat);
} catch (AudioProcessor.UnhandledAudioFormatException e) {
  // Speed adjustment unavailable for this encoding; reset to 1x or bypass Sonic
  playbackParameters = new PlaybackParameters(1f);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of google/ExoPlayer@dd430f7053 (2026-08-14). Data as JSON: /api/errors/d031c77fcdb6b388. Report an issue: GitHub.