When implementing the real-time voice call function in my customer service system, if I want to automatically play audio and video streams, I encountered problems on Apple devices.
Safari does not allow sounds to play automatically in the background by default. This is for user experience and privacy reasons, to avoid automatically playing sounds without the user realizing it.
The solution is
Safari browser for iOS 11 and above. When the user has had at least one interaction, the following two properties can be set, muted
and playsinline
the property . Then set the dynamic js to play the sound automatically
<audio id="myAudio" src="audio.mp3" muted playsinline></audio>
Then dynamically set the properties in js
var myAudio = document.getElementById('myAudio');
myAudio.muted = false; // 将 muted 属性设置为 false
myAudio.autoplay = true; // 将 autoplay 属性设置为 true
myAudio.play(); // 播放音频
so
After the page has at least one interaction, you can make the sound play automatically on the Apple device