function autoPlayMusic(selector) {
/* 自动播放音乐效果,解决浏览器或者APP自动播放问题 /
function musicInBrowserHandler() {
musicPlay(true, selector);
document.body.removeEventListener('touchstart', musicInBrowserHandler);
}
document.body.addEventListener('touchstart', musicInBrowserHandler);
/ 自动播放音乐效果,解决微信自动播放问题 */
function musicInWeixinHandler() {
musicPlay(true, selector);
document.addEventListener("WeixinJSBridgeReady", function() {
musicPlay(true, selector);
}, false);
document.removeEventListener('DOMContentLoaded', musicInWeixinHandler);
}
document.addEventListener('DOMContentLoaded', musicInWeixinHandler);
}
function musicPlay(isPlay, selector) {
var media = document.querySelector(selector);
if (isPlay && media.paused) {
media.play();
}
if (!isPlay && !media.paused) {
media.pause();
}
}
autoPlayMusic调用的时候必须写在(function(){
})()里面