H5音频自动播放

H5音频自动播放 兼容ios


<div class="box1" id="bx">
<div class="music" id="mui">
<span class="musict" onclick="bf()"></span>
</div>
</div>

<audio src="armof.mp3" id="au" autoplay='autoplay' loop="loop"></audio>

<script>

var au=document.getElementById('au');

var mui=document.getElementById('mui');

var ms=document.getElementById('musict');


au.src = "armof.mp3";//需要js引入路径
au.play();

// 音乐兼容微信自动播放
document.addEventListener('DOMContentLoaded', function () {
function audioAutoPlay() {
var au=document.getElementById('au');
au.play();
document.addEventListener("WeixinJSBridgeReady", function () {
au.play();
}, false);
}
audioAutoPlay();
});
document.addEventListener("WeixinJSBridgeReady", function () {
au.play();
}, false);

//点击一下停止 再点击一下播放功能

function bf(){
if(au.paused){
au.play();
}else{
au.pause();
}
}
var flag=true;
mui.onclick=function(){
if(flag){
mui.className='';
bx.className='';
flag = !flag;
}else{
mui.className='music';
bx.className='box1';
flag = !flag;
}
}

</script>

展开阅读全文

没有更多推荐了,返回首页