一、添加音乐
<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();