{"record":{"id":"e7be1fb11519a72e","repo":"google/ExoPlayer","slug":"audiotrackstate-audiotrack-state-initialized","errorCode":"audioTrackState != AudioTrack.STATE_INITIALIZED","errorMessage":"AudioTrack init failed {audioTrackState} Config({sampleRate}, {channelConfig}, {bufferSize}) {format}{isRecoverable? \\ (recoverable\\)}","messagePattern":"AudioTrack init failed (.+?) Config\\((.+?), (.+?), (.+?)\\) (.+?)(.+?)","errorType":"exception","errorClass":"AudioSink.InitializationException","httpStatus":null,"severity":"error","filePath":"library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java","lineNumber":2114,"sourceCode":"        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(\n            state,\n            outputSampleRate,\n            outputChannelConfig,\n            bufferSize,\n            inputFormat,\n            /* isRecoverable= */ outputModeIsOffload(),\n            /* audioTrackException= */ null);\n      }\n      return audioTrack;\n    }\n\n    private AudioTrack createAudioTrack(\n        boolean tunneling, AudioAttributes audioAttributes, int audioSessionId) {\n      if (Util.SDK_INT >= 29) {\n        return createAudioTrackV29(tunneling, audioAttributes, audioSessionId);\n      } else if (Util.SDK_INT >= 21) {\n        return createAudioTrackV21(tunneling, audioAttributes, audioSessionId);\n      } else {","sourceCodeStart":2096,"sourceCodeEnd":2132,"githubUrl":"https://github.com/google/ExoPlayer/blob/dd430f7053a1a3958deea3ead6a0565150c06bfc/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java#L2096-L2132","documentation":"After AudioTrack construction succeeds, DefaultAudioSink checks audioTrack.getState(); if it is not AudioTrack.STATE_INITIALIZED (commonly STATE_UNINITIALIZED or STATE_NO_STATIC_DATA after a native init failure), it releases the track and throws AudioSink.InitializationException carrying the actual state, sample rate, channel config, buffer size, and the input format. isRecoverable is true only in offload mode, signaling the player may retry without offload; otherwise the audio renderer is treated as failed for this sink configuration.","triggerScenarios":"The framework AudioTrack constructor returns an uninitialized track — native allocation failure, unsupported offload/passthrough configuration accepted by the constructor but rejected during init, or resource exhaustion (too many tracks open).","commonSituations":"Low-memory conditions exhausting AudioTrack/AF Track objects; OEM audio HAL limits on concurrent compressed outputs; switching quickly between offload and normal items in a playlist; devices with buggy audio HALs reporting STATE_UNINITIALIZED for valid configs.","solutions":["Handle PlaybackException with ERROR_CODE_AUDIO_TRACK_INIT_FAILED: if the underlying InitializationException.isRecoverable(), retry playback with offload disabled.","Release and rebuild the player when this fires repeatedly (HAL resource leaks usually clear after releasing the AudioTrack).","Reduce simultaneous player/AudioTrack instances (e.g. preloading pools) to avoid native track exhaustion.","Capture audioTrackState and format from the exception for the bug report; test the same media on other devices to isolate HAL issues."],"exampleFix":"// before\nplayer.addListener(new Player.Listener() {}); // no error handling\n\n// after\nplayer.addListener(new Player.Listener() {\n  @Override public void onPlayerError(PlaybackException error) {\n    if (error.getErrorCode()\n        == PlaybackException.ERROR_CODE_AUDIO_TRACK_INIT_FAILED) {\n      // rebuild player without offload and retry current item\n      restartWithoutOffload(player.getCurrentMediaItem());\n    }\n  }\n});","handlingStrategy":"fallback","validationCode":"AudioTrack probe = buildProbeTrack(encoding, sampleRate, channelConfig, bufferBytes);\nint state = probe.getState();\nprobe.release();\nif (state != AudioTrack.STATE_INITIALIZED) {\n  // plan PCM fallback now, before attaching the item to the player\n}","typeGuard":null,"tryCatchPattern":"player.addListener(new Player.Listener() {\n  @Override public void onPlayerError(PlaybackException e) {\n    if (e.getErrorCode()\n        == PlaybackException.ERROR_CODE_AUDIO_TRACK_INIT_FAILED) {\n      releaseAndRebuildPlayer(currentMediaItem); // clears native track leak\n    }\n  }\n});","preventionTips":["Cap simultaneous players/AudioTracks to avoid native exhaustion","Treat repeated STATE_UNINITIALIZED on one device as HAL bug — collect diagnostics","Always release players on backgrounding to free AudioTrack resources"],"tags":["exoplayer","audio","audiotrack","initialization","hal","resource-exhaustion"],"backgroundTag":null,"analyzedSha":"dd430f7053a1a3958deea3ead6a0565150c06bfc","analyzedAt":"2026-08-14T12:22:02.982Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}