DrKLO/Telegram · error · InitializationException

AudioTrack init failed {audioTrackState} Config({sampleRate}

Error message

AudioTrack init failed {audioTrackState} Config({sampleRate}, {channelConfig}, {bufferSize}) (recoverable)

What it means

In DefaultAudioSink.AudioTrackFactory.buildAudioTrack, createAudioTrack(...) throwing UnsupportedOperationException or IllegalArgumentException is wrapped into InitializationException with isRecoverable = outputModeIsOffload(). This signals the platform refused to construct an AudioTrack in the chosen output mode (commonly offload/tunneling). Recovery is allowed only when the failure occurred in offload mode, letting the caller retry in a non-offload mode.

Source

Thrown at TMessagesProj/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java:2130

          && audioTrackConfiguration.outputPcmFrameSize == outputPcmFrameSize;
    }

    public long inputFramesToDurationUs(long frameCount) {
      return (frameCount * C.MICROS_PER_SECOND) / inputFormat.sampleRate;
    }

    public long framesToDurationUs(long frameCount) {
      return (frameCount * C.MICROS_PER_SECOND) / outputSampleRate;
    }

    public AudioTrack buildAudioTrack(
        boolean tunneling, AudioAttributes audioAttributes, int audioSessionId)
        throws InitializationException {
      AudioTrack audioTrack;
      try {
        audioTrack = createAudioTrack(tunneling, audioAttributes, audioSessionId);
      } catch (UnsupportedOperationException | IllegalArgumentException e) {
        throw new InitializationException(
            AudioTrack.STATE_UNINITIALIZED,
            outputSampleRate,
            outputChannelConfig,
            bufferSize,
            inputFormat,
            /* isRecoverable= */ outputModeIsOffload(),
            e);
      }

      int state = audioTrack.getState();
      if (state != AudioTrack.STATE_INITIALIZED) {
        try {
          audioTrack.release();
        } catch (Exception e) {
          // The track has already failed to initialize, so it wouldn't be that surprising if
          // release were to fail too. Swallow the exception.
        }
        throw new InitializationException(

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Catch InitializationException and, when isRecoverable() is true, retry sink configuration with offload disabled (force PCM decode or standard path).
  2. Verify the device supports offload for the codec before enabling OUTPUT_MODE_OFFLOAD.
  3. Use DefaultAudioSink.Builder.setEnableOffload(false) on known-incompatible devices.

Example fix

// before
sink.configure(format); // offload enabled

// after
try {
  sink.configure(format);
} catch (AudioSink.InitializationException e) {
  if (e.isRecoverable) { /* retry with offload disabled */ }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// probe offload support before enabling it
boolean offloadOk = useOffloadedPlayback(format, audioAttributes) && deviceSupportsOffload(format);
if (!offloadOk) { sinkBuilder.setEnableOffload(false); }

Try / catch

try { sink.configure(format, /* isOffload= */ true, attrs); }
catch (AudioSink.InitializationException e) {
  if (e.isRecoverable) { sink.configure(format, /* isOffload= */ false, attrs); }
}

Prevention

When it happens

Trigger: createAudioTrack (AudioTrack construction, possibly with PERFORMANCE_MODE/transfer mode/offload flags) raises UnsupportedOperationException/IllegalArgumentException on a device that does not support the requested mode/encoding.

Common situations: Requesting audio offload on a device whose kernel/AudioFlinger does not support it for the codec; tunneling session id mismatch; constructing an offloaded track for an encoding the HAL rejects.

Related errors


AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14). Data as JSON: /api/errors/5208f4f116eaf2e3. Report an issue: GitHub.