Audio在移动端的兼容性问题
https://www.jianshu.com/p/b26cdf3a96f2?from=timeline&isappinstalled=0
https://www.jianshu.com/p/1b94dde73574
/* 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');
var isPlaying = myaudio.currentTime > 0 && !myaudio.paused && !myaudio.ended && myaudio.readyState > 2;
if (!isPlaying) {
setTimeout(function () {
myaudio.play().catch(function (e) {
console.log("", e.message);
console.log("", e.description);
});
}, 150);
} else {
alert("网络缓慢,正在加载音频...");
} */
The play() request was interrupted by a call to pause()
play() failed because the user didn’t interact with the document first.
一个项目源码;
https://github.com/orbem/vue-music-webapp
https://github.com/orbem/vue-music-webapp/blob/master/src/App.vue