处理iphone的 .play() 不能播放问题

一、添加音乐

<audio id="Jaudio" src="shake.mp3" preload loop="loop" controls="controls"></audio >

二、处理兼容

    function audioAutoPlay(id){
            var audio = document.getElementById(id);

            var play = function() {
                document.removeEventListener("WeixinJSBridgeReady", play);
                document.removeEventListener("YixinJSBridgeReady", play);

                audio.play();
                audio.pause();
                // document.removeEventListener("touchstart", play, false);
            };
            
            audio.play();
            audio.pause();

            //weixin
            document.addEventListener("WeixinJSBridgeReady", play, false);
            //yixin
            document.addEventListener('YixinJSBridgeReady', play, false);
            // document.addEventListener("touchstart", play, false);
            alert(222)
        }
        audioAutoPlay('Jaudio');  

三、开始播放

 var audio = document.getElementById('Jaudio');
 audio.play();

 

posted @ 2018-06-27 09:28  Candy-Yao  阅读(1228)  评论(0编辑  收藏  举报