vue移动端用audio做背景音乐

我遇到的坑,主要就是移动端的问题和切换路由导致背景音乐暂停的问题

者可以用一个套路来解决:把audio卸载index.html中,写下来上代码

1,html部分

2,js部分

在index.html底部添加一个script标签,用来监听事件,使音乐自动播放

function audioAutoPlay(id){        
    var audio = document.getElementById(id),            
    play = function(){                
        audio.play();                
        document.removeEventListener("touchstart",play, false);            
    };        
    audio.play();       
    document.addEventListener("WeixinJSBridgeReady", function () {            
      play();        
    }, false);        
    document.addEventListener('YixinJSBridgeReady', function() {            
      play();        
    }, false);        
    document.addEventListener("touchstart",play, false);    
    }    
    audioAutoPlay('myaudio');

猜你喜欢

转载自blog.csdn.net/liuguochao1024/article/details/82882412