{"record":{"id":"ddba0b3e278f765d","repo":"google/ExoPlayer","slug":"no-mixing-matrix-for-input-channel-count-audiofor","errorCode":null,"errorMessage":"No mixing matrix for input channel count {audioFormat}","messagePattern":"No mixing matrix for input channel count (.+?)","errorType":"exception","errorClass":"UnhandledAudioFormatException","httpStatus":null,"severity":"error","filePath":"library/common/src/main/java/com/google/android/exoplayer2/audio/ChannelMixingAudioProcessor.java","lineNumber":66,"sourceCode":"   * ChannelMixingMatrix#getInputChannelCount() channel count}. Overwrites any previously stored\n   * matrix for the same input channel count.\n   */\n  public void putChannelMixingMatrix(ChannelMixingMatrix matrix) {\n    int inputChannelCount = matrix.getInputChannelCount();\n    matrixByInputChannelCount.put(inputChannelCount, matrix);\n  }\n\n  @Override\n  protected AudioFormat onConfigure(AudioFormat inputAudioFormat)\n      throws UnhandledAudioFormatException {\n    if (inputAudioFormat.encoding != C.ENCODING_PCM_16BIT) {\n      throw new UnhandledAudioFormatException(inputAudioFormat);\n    }\n    @Nullable\n    ChannelMixingMatrix channelMixingMatrix =\n        matrixByInputChannelCount.get(inputAudioFormat.channelCount);\n    if (channelMixingMatrix == null) {\n      throw new UnhandledAudioFormatException(\n          \"No mixing matrix for input channel count\", inputAudioFormat);\n    }\n    if (channelMixingMatrix.isIdentity()) {\n      return AudioFormat.NOT_SET;\n    }\n    return new AudioFormat(\n        inputAudioFormat.sampleRate,\n        channelMixingMatrix.getOutputChannelCount(),\n        C.ENCODING_PCM_16BIT);\n  }\n\n  @Override\n  public void queueInput(ByteBuffer inputBuffer) {\n    ChannelMixingMatrix channelMixingMatrix =\n        checkStateNotNull(matrixByInputChannelCount.get(inputAudioFormat.channelCount));\n\n    int inputFramesToMix = inputBuffer.remaining() / inputAudioFormat.bytesPerFrame;\n    ByteBuffer outputBuffer =","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/google/ExoPlayer/blob/dd430f7053a1a3958deea3ead6a0565150c06bfc/library/common/src/main/java/com/google/android/exoplayer2/audio/ChannelMixingAudioProcessor.java#L48-L84","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","solutions":["Pre-register matrices for every channel count your app can encounter: for (int ch = 1; ch <= 8; ch++) mixer.putChannelMixingMatrix(ChannelMixingMatrix.create(ch, targetChannels));","Register ChannelMixingMatrix.create(inputChannels, inputChannels) (identity) as a safe default for counts you do not actually want to remix.","Catch UnhandledAudioFormatException at configure time to skip mixing for unexpected channel counts."],"exampleFix":"// before\nmixer.putChannelMixingMatrix(ChannelMixingMatrix.create(2, 1));\n// 6-channel input -> UnhandledAudioFormatException\n\n// after\nfor (int ch = 1; ch <= 8; ch++) {\n  mixer.putChannelMixingMatrix(ch == 2\n      ? ChannelMixingMatrix.create(2, 1)\n      : ChannelMixingMatrix.create(ch, ch)); // identity passthrough\n}","handlingStrategy":"validation","validationCode":"boolean hasMatrix = false;\nfor (int ch = 1; ch <= 8; ch++) {\n  if (ch == inputFormat.channelCount) { hasMatrix = true; break; }\n}\nif (!hasMatrix) mixer.putChannelMixingMatrix(\n    ChannelMixingMatrix.create(inputFormat.channelCount, inputFormat.channelCount));","typeGuard":null,"tryCatchPattern":"try {\n  mixer.configure(inputFormat);\n} catch (AudioProcessor.UnhandledAudioFormatException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"mixing matrix\")) {\n    mixer.putChannelMixingMatrix(\n        ChannelMixingMatrix.create(\n            inputFormat.channelCount, inputFormat.channelCount));\n    mixer.configure(inputFormat);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Register matrices for every channel count your app can play (1 through 8 is a safe range).","Register identity matrices as harmless defaults for counts you do not want to remix.","Unit-test configure() with mono, stereo, 5.1 and 8-channel fixtures."],"tags":["exoplayer","media3","audio","channel-mixing","configuration"],"backgroundTag":null,"analyzedSha":"dd430f7053a1a3958deea3ead6a0565150c06bfc","analyzedAt":"2026-08-14T12:22:02.982Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}