{"record":{"id":"5208f4f116eaf2e3","repo":"DrKLO/Telegram","slug":"audiotrack-init-failed-audiotrackstate-config-s","errorCode":null,"errorMessage":"AudioTrack init failed {audioTrackState} Config({sampleRate}, {channelConfig}, {bufferSize}) (recoverable)","messagePattern":"AudioTrack init failed (.+?) Config\\((.+?), (.+?), (.+?)\\) \\(recoverable\\)","errorType":"exception","errorClass":"InitializationException","httpStatus":null,"severity":"error","filePath":"TMessagesProj/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java","lineNumber":2130,"sourceCode":"          && audioTrackConfiguration.outputPcmFrameSize == outputPcmFrameSize;\n    }\n\n    public long inputFramesToDurationUs(long frameCount) {\n      return (frameCount * C.MICROS_PER_SECOND) / inputFormat.sampleRate;\n    }\n\n    public long framesToDurationUs(long frameCount) {\n      return (frameCount * C.MICROS_PER_SECOND) / outputSampleRate;\n    }\n\n    public AudioTrack buildAudioTrack(\n        boolean tunneling, AudioAttributes audioAttributes, int audioSessionId)\n        throws InitializationException {\n      AudioTrack audioTrack;\n      try {\n        audioTrack = createAudioTrack(tunneling, audioAttributes, audioSessionId);\n      } catch (UnsupportedOperationException | IllegalArgumentException e) {\n        throw new InitializationException(\n            AudioTrack.STATE_UNINITIALIZED,\n            outputSampleRate,\n            outputChannelConfig,\n            bufferSize,\n            inputFormat,\n            /* isRecoverable= */ outputModeIsOffload(),\n            e);\n      }\n\n      int state = audioTrack.getState();\n      if (state != AudioTrack.STATE_INITIALIZED) {\n        try {\n          audioTrack.release();\n        } catch (Exception e) {\n          // The track has already failed to initialize, so it wouldn't be that surprising if\n          // release were to fail too. Swallow the exception.\n        }\n        throw new InitializationException(","sourceCodeStart":2112,"sourceCodeEnd":2148,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java#L2112-L2148","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Catch InitializationException and, when isRecoverable() is true, retry sink configuration with offload disabled (force PCM decode or standard path).","Verify the device supports offload for the codec before enabling OUTPUT_MODE_OFFLOAD.","Use DefaultAudioSink.Builder.setEnableOffload(false) on known-incompatible devices."],"exampleFix":"// before\nsink.configure(format); // offload enabled\n\n// after\ntry {\n  sink.configure(format);\n} catch (AudioSink.InitializationException e) {\n  if (e.isRecoverable) { /* retry with offload disabled */ }\n}","handlingStrategy":"try-catch","validationCode":"// probe offload support before enabling it\nboolean offloadOk = useOffloadedPlayback(format, audioAttributes) && deviceSupportsOffload(format);\nif (!offloadOk) { sinkBuilder.setEnableOffload(false); }","typeGuard":null,"tryCatchPattern":"try { sink.configure(format, /* isOffload= */ true, attrs); }\ncatch (AudioSink.InitializationException e) {\n  if (e.isRecoverable) { sink.configure(format, /* isOffload= */ false, attrs); }\n}","preventionTips":["Verify device offload support per-codec before enabling OUTPUT_MODE_OFFLOAD.","Always implement the isRecoverable retry path to PCM/non-offload.","Maintain a deny-list of known-incompatible devices for offload."],"tags":["audio","exoplayer","audiotrack","offload","initialization","recoverable"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}