google/ExoPlayer · error · AudioSink.ConfigurationException

Invalid output encoding (mode=%s) for: %s

Error message

Invalid output encoding (mode=%s) for: %s

What it means

After selecting an output encoding for the AudioTrack (PCM, passthrough, or offload mode), DefaultAudioSink validates the resolved encoding. If outputEncoding equals C.ENCODING_INVALID — meaning mode computation produced no usable encoding at all, such as an unrecognized MIME type when deriving an offload encoding or an unset PCM encoding — it throws ConfigurationException('Invalid output encoding (mode=...) for: <format>') from AudioSink.configure.

Source

Thrown at library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java:727

      } else {
        outputMode = OUTPUT_MODE_PASSTHROUGH;
        @Nullable
        Pair<Integer, Integer> encodingAndChannelConfig =
            getAudioCapabilities().getEncodingAndChannelConfigForPassthrough(inputFormat);
        if (encodingAndChannelConfig == null) {
          throw new ConfigurationException(
              "Unable to configure passthrough for: " + inputFormat, inputFormat);
        }
        outputEncoding = encodingAndChannelConfig.first;
        outputChannelConfig = encodingAndChannelConfig.second;
        // Passthrough only supports AudioTrack playback parameters, but we only enable it this was
        // specifically requested by the app.
        enableAudioTrackPlaybackParams = preferAudioTrackPlaybackParams;
      }
    }

    if (outputEncoding == C.ENCODING_INVALID) {
      throw new ConfigurationException(
          "Invalid output encoding (mode=" + outputMode + ") for: " + inputFormat, inputFormat);
    }
    if (outputChannelConfig == AudioFormat.CHANNEL_INVALID) {
      throw new ConfigurationException(
          "Invalid output channel config (mode=" + outputMode + ") for: " + inputFormat,
          inputFormat);
    }
    int bufferSize =
        specifiedBufferSize != 0
            ? specifiedBufferSize
            : audioTrackBufferSizeProvider.getBufferSizeInBytes(
                getAudioTrackMinBufferSize(outputSampleRate, outputChannelConfig, outputEncoding),
                outputEncoding,
                outputMode,
                outputPcmFrameSize != C.LENGTH_UNSET ? outputPcmFrameSize : 1,
                outputSampleRate,
                inputFormat.bitrate,
                enableAudioTrackPlaybackParams ? MAX_PLAYBACK_SPEED : DEFAULT_PLAYBACK_SPEED);

View on GitHub (pinned to dd430f7053)

Solutions

  1. Disable audio offload for formats not in the platform offload list (DefaultAudioSink offload preferences or track-selector constraints).
  2. Verify Format.sampleMimeType is a known audio type (MimeTypes.isAudio) before it reaches the sink; log the failing Format from the exception.
  3. Catch ConfigurationException at playback start and retry with a sink built without offload enabled.
  4. On API < 33 keep offload off unless the exact codec (e.g. MP3/AAC/FLAC/OPUS) is confirmed supported by the device's AudioManager.isOffloadedPlaybackSupported.

Example fix

// before — offload for all audio
DefaultAudioSink audioSink =
    new DefaultAudioSink.Builder(ctx)
        .setOffloadMode(DefaultAudioSink.OFFLOAD_MODE_ENABLED_ALWAYS)
        .build();

// after — offload only when the platform confirms support
AudioManager am = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
boolean offload = am != null
    && am.isOffloadedPlaybackSupported(new AudioAttributes.Builder()
        .setUsage(AudioAttributes.USAGE_MEDIA).build(),
        new AudioFormat.Builder().setEncoding(AudioFormat.ENCODING_AAC_LC)
            .setSampleRate(44_100).setChannelMask(AudioFormat.CHANNEL_OUT_STEREO).build());
DefaultAudioSink audioSink =
    new DefaultAudioSink.Builder(ctx)
        .setOffloadMode(offload
            ? DefaultAudioSink.OFFLOAD_MODE_ENABLED_ALWAYS
            : DefaultAudioSink.OFFLOAD_MODE_DISABLED)
        .build();
Defensive patterns

Strategy: validation

Validate before calling

int encoding = MimeTypes.getEncoding(format.sampleMimeType, format.codecs);
if (encoding == C.ENCODING_INVALID) {
  // this format cannot drive an AudioTrack: choose PCM decode / reject item
}

Try / catch

try {
  player.setMediaItem(offloadItem);
} catch (PlaybackException e) {
  if (e.getErrorCode()
      == PlaybackException.ERROR_CODE_AUDIO_TRACK_INIT_FAILED) {
    rebuildSinkWithoutOffload(offloadItem);
  }
}

Prevention

When it happens

Trigger: Configuring the sink with a Format whose sample MIME type maps to no audio encoding (MimeTypes.getEncoding returns ENCODING_INVALID) — e.g. enabling audio offload for a codec the platform does not recognize, or a custom/unknown sampleMimeType reaching the sink.

Common situations: setEnableAudioOffload(true) with container/codec combos outside the supported offload set; playlists mixing known and exotic codecs; custom MediaSource or Icy metadata wrappers that mangle Format.sampleMimeType; API-level differences in supported offload encodings.

Related errors


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