Why can't JavaScript .play() audio files on iPhone safari?

后端 未结 4 1875
慢半拍i
慢半拍i 2020-12-08 06:51

I\'ve got a JavaScript web app working that plays some audio periodically like this:

var SOUND_SUCCESS = new Audio(\'success.mp3\');
SOUND_SUCCESS.play();
         


        
4条回答
  •  生来不讨喜
    2020-12-08 07:25

    iOS disables autoplay, instead requiring that play be initiated as part of a user interaction (e.g., you can start playback within a touchstart listener). There's a bit of documentation about this on Apple's developer documentation. There's also this article Overcoming iOS HTML5 audio limitations on IBM's developer site that has examples and more detail.

提交回复
热议问题