Sound problem on iPhone. The sound is played every other time

Hi guys! I have a problem. I’m currently making a game for the web and I’m trying to make it so that when the window is minimized, the sound will stop playing, and when the window is active, the sound will start playing again.

I did this for a laptop and an Android phone, but on the iPhone the sound works strangely. When the game starts, the sound starts playing. When I minimize the browser the sound stops. But when opening the browser, the sound resumes every other time. I upload mp3 as sound.

Let’s say I open the browser again, the sound does not play. I minimize and maximize the browser, the sound plays. And this is constantly repeated.

I tried using music playback and audio playback in the conditions, I used a plugin, but nothing helped. Maybe you have some ideas?

Let’s take a look at this game. If you open it on your iPhone and minimize and maximize the browser several times, sometimes the sound will not play.

Does this happen to everyone?
How to solve this problem?