{"record":{"id":"9b81dbeaadef3183","repo":"google/ExoPlayer","slug":"unhandled-input-format-inputaudioformat-9b81db","errorCode":null,"errorMessage":"Unhandled input format: {inputAudioFormat}","messagePattern":"Unhandled input format: (.+?)","errorType":"exception","errorClass":"AudioProcessor.UnhandledAudioFormatException","httpStatus":null,"severity":"error","filePath":"library/core/src/main/java/com/google/android/exoplayer2/audio/TrimmingAudioProcessor.java","lineNumber":84,"sourceCode":"\n  /** Sets the trimmed frame count returned by {@link #getTrimmedFrameCount()} to zero. */\n  public void resetTrimmedFrameCount() {\n    trimmedFrameCount = 0;\n  }\n\n  /**\n   * Returns the number of audio frames trimmed since the last call to {@link\n   * #resetTrimmedFrameCount()}.\n   */\n  public long getTrimmedFrameCount() {\n    return trimmedFrameCount;\n  }\n\n  @Override\n  public AudioFormat onConfigure(AudioFormat inputAudioFormat)\n      throws UnhandledAudioFormatException {\n    if (inputAudioFormat.encoding != OUTPUT_ENCODING) {\n      throw new UnhandledAudioFormatException(inputAudioFormat);\n    }\n    reconfigurationPending = true;\n    return trimStartFrames != 0 || trimEndFrames != 0 ? inputAudioFormat : AudioFormat.NOT_SET;\n  }\n\n  @Override\n  public void queueInput(ByteBuffer inputBuffer) {\n    int position = inputBuffer.position();\n    int limit = inputBuffer.limit();\n    int remaining = limit - position;\n\n    if (remaining == 0) {\n      return;\n    }\n\n    // Trim any pending start bytes from the input buffer.\n    int trimBytes = min(remaining, pendingTrimStartBytes);\n    trimmedFrameCount += trimBytes / inputAudioFormat.bytesPerFrame;","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/google/ExoPlayer/blob/dd430f7053a1a3958deea3ead6a0565150c06bfc/library/core/src/main/java/com/google/android/exoplayer2/audio/TrimmingAudioProcessor.java#L66-L102","documentation":"TrimmingAudioProcessor removes a fixed number of frames from the start and end of each audio stream (used for gapless playback trim metadata from containers like MP4/M4A). It only operates on its fixed OUTPUT_ENCODING (16-bit PCM); onConfigure throws UnhandledAudioFormatException for anything else, because sample-accurate trimming is implemented on 16-bit samples only.","triggerScenarios":"Media carries trim metadata (e.g. gapless info in ID3/MP4) so the player configures trimming, but the decoded audio is 24/32-bit PCM or float, not 16-bit.","commonSituations":"Playing gapless-annotated FLAC/ALAC files whose decoder outputs high-res PCM; custom decoders emitting float; version changes in which trim metadata parsing became enabled by default for more containers.","solutions":["Clear trim metadata before playback for high-res content (e.g. use MediaItem.Builder with a cloned Format or a custom MediaSource that strips gapless info).","Force the decode chain to 16-bit PCM so trimming can operate (accept the quality downgrade).","Catch the configuration failure and retry without gapless trimming.","If authoring content, encode gapless high-res files without trim tags or as 16-bit."],"exampleFix":"// before — trim metadata from a 24-bit FLAC triggers the processor\nMediaItem item = MediaItem.fromUri(flacWithGaplessTags);\n\n// after — strip gapless/trim metadata so the processor stays inactive\nMediaMetadata stripped = mediaMetadata.buildUpon()\n    .setExtras(null)\n    .build();\n// or bypass via ExtractorsFactory that ignores gapless info for high-res PCM","handlingStrategy":"validation","validationCode":"static boolean trimSafe(Format format) {\n  // trimming operates on 16-bit PCM only\n  return format.pcmEncoding == C.ENCODING_PCM_16BIT\n      || (MimeTypes.AUDIO_RAW.equals(format.sampleMimeType)\n          && format pcmEncoding unset for 16-bit);\n}\n// strip gapless/trim metadata before playback when !trimSafe(format)","typeGuard":null,"tryCatchPattern":"try {\n  player.setMediaItem(gaplessItem);\n} catch (Exception e) { // surfaces as ConfigurationException on configure\n  player.setMediaItem(stripTrimMetadata(gaplessItem));\n}","preventionTips":["Strip gapless trim tags for high-res/float content at MediaItem build time","Re-encode gapless-critical catalogs to 16-bit if trimming matters","Log pcmEncoding per track during QA to catch mismatched pipelines"],"tags":["exoplayer","audio","pcm","gapless","trimming","configuration"],"backgroundTag":null,"analyzedSha":"dd430f7053a1a3958deea3ead6a0565150c06bfc","analyzedAt":"2026-08-14T12:22:02.982Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}