Home >Web Front-end >H5 Tutorial >Sharing of problems encountered when ios loads html5 audio tags
html5
audio
Tags cannot be played automatically in the ios WeChat browser. I recently encountered this problem while working on a small project. It is normal on both Android and PC. Only ios doesn't work. I checked a lot of information and found the following method. It may not be the best method to use. If there is a more convenient method, please leave a message:
##
html部分: <audio id="audio"><source src="20161012102044_57fd9dfc044cd.mp3"></audio> <script> audio = document.getElementById('audio'); audio.play(); </script>
js part:
// 函数: function audioAutoPlay(id) { var audio = document.getElementById(id); var play = function() { document.removeEventListener("WeixinJSBridgeReady", play); document.removeEventListener("YixinJSBridgeReady", play); // document.removeEventListener("touchstart", play, false); audio.play(); audio.pause(); }; audio.play(); audio.pause(); //weixin document.addEventListener("WeixinJSBridgeReady", play, false); //yixin document.addEventListener('YixinJSBridgeReady', play, false); //touch document.addEventListener("touchstart", play, false); } //调用: audioAutoPlay('audio1');
The above is the detailed content of Sharing of problems encountered when ios loads html5 audio tags. For more information, please follow other related articles on the PHP Chinese website!