Home >Web Front-end >H5 Tutorial >Sharing of problems encountered when ios loads html5 audio tags

Sharing of problems encountered when ios loads html5 audio tags

零下一度
零下一度Original
2017-06-29 10:12:142125browse

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>


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;);


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!

Statement:
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