audio标签自动播放在安卓播放正常,IOS不能自动播放

audio标签自动播放在安卓播放正常,IOS不能自动播放
    class="musicPic" src="./music.png" id="musicIcon" />
        

解决办法:

 //微信自动播放 
        function audioAutoPlay(){   
                      
            play = function(){  
                musicPlay.play();  
                document.removeEventListener("touchstart",play, false);  
            };   
            document.addEventListener("WeixinJSBridgeReady", function () {  
                play();  
            }, false);  
            document.addEventListener('YixinJSBridgeReady', function() {  
                play();  
            }, false);
            document.addEventListener("touchstart",play, false);  
        }  
        audioAutoPlay();   
        //点击图片播放暂停
        musicIcon.bind("click",function(){
            console.log(musicPlay)
            if(musicState === "on"){
                musicPlay.pause();
                musicState = "off";
            }else{
                musicPlay.play();
                musicState = "on";
            }
        });

 

posted on 2017-12-18 13:06  麦田里的包米 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/guanguan-/p/8057043.html

你可能感兴趣的:(audio标签自动播放在安卓播放正常,IOS不能自动播放)