audio標籤自動播放在安卓播放正常,IOS不能自動播放

    <img class="musicPic" src="./music.png" id="musicIcon" />
        <audio style="display: none;" autoplay="autoplay" id="autoplay" controls="controls"loop="loop" preload="auto"
                    src="{{detail.backGroundMusic}}">
              你的瀏覽器不支持audio標籤
        </audio>

解決辦法:瀏覽器

 //微信自動播放 
        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";
            }
        });
相關文章
相關標籤/搜索