This behavior appears to stem from a latent audio session configuration issue within AVAudioPlayer, particularly noticeable on first playback attempts when routing audio over Bluetooth. Despite some recommendations on Stack Overflow, invoking play() on a background or serial queue has no measurable impact on the delay.
Through repeated testing, I’ve consistently observed that the initial playback results in a delay of approximately two seconds, during which the audio seems to discover the external speaker and then transitions to the correct Bluetooth output while the player progresses through audio playback. This only occurs during the first use of AVAudioPlayer; all subsequent plays perform as expected.
The most effective workaround I’ve found is to immediately play a short silent audio clip after application launch. This appears to pre-initialize the audio session and forces the underlying audio routing to be resolved early, avoiding the lag during actual user-initiated playback.
While not at all ideal (the solution makes me cringe), this approach has proven stable and effective.
Topic:
Media Technologies
SubTopic:
Audio
Tags: