Home > Web Front-end > H5 Tutorial > body text

Sharing of problems encountered when ios loads html5 audio tags

零下一度
Release: 2017-06-29 10:12:14
Original
2079 people have browsed it

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(&#39;audio&#39;);
    audio.play();
</script>
Copy after login


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(&#39;YixinJSBridgeReady&#39;, play, false);
    //touch   document.addEventListener("touchstart", play, false);
}
//调用:
audioAutoPlay(&#39;audio1&#39;);
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!