google/ExoPlayer · error · UnhandledAudioFormatException

No mixing matrix for input channel count {audioFormat}

Error message

No mixing matrix for input channel count {audioFormat}

What it means

ChannelMixingAudioProcessor looks up a ChannelMixingMatrix by input channel count in matrixByInputChannelCount. If none was registered for that count, onConfigure throws UnhandledAudioFormatException with 'No mixing matrix for input channel count' plus the format. The processor ships with no default matrices: you must call putChannelMixingMatrix(...) for every input channel count you intend to accept.

Source

Thrown at library/common/src/main/java/com/google/android/exoplayer2/audio/ChannelMixingAudioProcessor.java:66

   * ChannelMixingMatrix#getInputChannelCount() channel count}. Overwrites any previously stored
   * matrix for the same input channel count.
   */
  public void putChannelMixingMatrix(ChannelMixingMatrix matrix) {
    int inputChannelCount = matrix.getInputChannelCount();
    matrixByInputChannelCount.put(inputChannelCount, matrix);
  }

  @Override
  protected AudioFormat onConfigure(AudioFormat inputAudioFormat)
      throws UnhandledAudioFormatException {
    if (inputAudioFormat.encoding != C.ENCODING_PCM_16BIT) {
      throw new UnhandledAudioFormatException(inputAudioFormat);
    }
    @Nullable
    ChannelMixingMatrix channelMixingMatrix =
        matrixByInputChannelCount.get(inputAudioFormat.channelCount);
    if (channelMixingMatrix == null) {
      throw new UnhandledAudioFormatException(
          "No mixing matrix for input channel count", inputAudioFormat);
    }
    if (channelMixingMatrix.isIdentity()) {
      return AudioFormat.NOT_SET;
    }
    return new AudioFormat(
        inputAudioFormat.sampleRate,
        channelMixingMatrix.getOutputChannelCount(),
        C.ENCODING_PCM_16BIT);
  }

  @Override
  public void queueInput(ByteBuffer inputBuffer) {
    ChannelMixingMatrix channelMixingMatrix =
        checkStateNotNull(matrixByInputChannelCount.get(inputAudioFormat.channelCount));

    int inputFramesToMix = inputBuffer.remaining() / inputAudioFormat.bytesPerFrame;
    ByteBuffer outputBuffer =

View on GitHub (pinned to dd430f7053)

Solutions

  1. Pre-register matrices for every channel count your app can encounter: for (int ch = 1; ch <= 8; ch++) mixer.putChannelMixingMatrix(ChannelMixingMatrix.create(ch, targetChannels));
  2. Register ChannelMixingMatrix.create(inputChannels, inputChannels) (identity) as a safe default for counts you do not actually want to remix.
  3. Catch UnhandledAudioFormatException at configure time to skip mixing for unexpected channel counts.

Example fix

// before
mixer.putChannelMixingMatrix(ChannelMixingMatrix.create(2, 1));
// 6-channel input -> UnhandledAudioFormatException

// after
for (int ch = 1; ch <= 8; ch++) {
  mixer.putChannelMixingMatrix(ch == 2
      ? ChannelMixingMatrix.create(2, 1)
      : ChannelMixingMatrix.create(ch, ch)); // identity passthrough
}
Defensive patterns

Strategy: validation

Validate before calling

boolean hasMatrix = false;
for (int ch = 1; ch <= 8; ch++) {
  if (ch == inputFormat.channelCount) { hasMatrix = true; break; }
}
if (!hasMatrix) mixer.putChannelMixingMatrix(
    ChannelMixingMatrix.create(inputFormat.channelCount, inputFormat.channelCount));

Try / catch

try {
  mixer.configure(inputFormat);
} catch (AudioProcessor.UnhandledAudioFormatException e) {
  if (e.getMessage() != null && e.getMessage().contains("mixing matrix")) {
    mixer.putChannelMixingMatrix(
        ChannelMixingMatrix.create(
            inputFormat.channelCount, inputFormat.channelCount));
    mixer.configure(inputFormat);
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Calling putChannelMixingMatrix(ChannelMixingMatrix.create(2, 1)) (stereo-to-mono only) and then playing 6-channel (5.1) content, or forgetting to register any matrix at all before configure().

Common situations: App registers stereo-only mixing and the user plays multichannel audio (5.1 AAC, 8-channel WAV); device audio framework hands a different channel count after route changes; unit tests using mono fixtures while production registers stereo matrices.

Related errors


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