Start Sound Audio on Pointer Down to Avoid Late Playback on Taps
A soundboard's audio must begin within milliseconds of a tap, or users perceive delay, missed taps, or duplicate sounds. The author explains that browsers grant audio permission only during the synchronous turn of a user gesture, so awaiting AudioContext.resume() before calling play() can cause playback to fail or require a second tap. On mobile, the click event often fires late or not at all when a tap is interpreted as a scroll, making it an unreliable trigger. The recommended approach is to listen to earlier events such as pointerdown, with touchend as an option for older browsers, and keep click only as a fallback. The author also provides a small tested JavaScript helper that decides whether a context needs resuming and whether playback should start immediately.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in