'Mobile Safari skips first seconds of HTML Audio on play()

I have an React Audio Player that uses a useAudio hook to manage the HTML5 audio. It works fine everywhere except Mobile Safari, where the sound begins a few seconds after the player starts playing.

What's odd is that I'm checking canplaythrough on the element before calling HTMLAudioElement.play(). So Safari fires canplaythrough and starts "playing" the audio, except that the audio doesn't actually start until a second or so in.

Here's a complete example on CodeSandbox: https://codesandbox.io/s/useaudioplayer-jvftw?file=/src/useAudio.tsx

To replicate, open in Mobile Safari and play the Audio.



Solution 1:[1]

In my case audio would play ok the 1st time.
And from the 2nd time and on, safari would skip some initial seconds.

Solved it by calling
myAudio.load();
just before
myAudio.play();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pok_net