HTML
<audio id="myaudio" src="../music.mp3" controls="controls" hidden="true"></audio>
JS
//播放按钮标签,循环次数播放,间隔时间 function hwhAudioPlay(elem,max,times){ elem.play(); var start = 0; elem.addEventListener("ended",function() { start++; if (start<max) { setTimeout(function(){elem.play();},times); }else{ elem.pause(); } }); } var myAuto = document.getElementById('myaudio'); hwhAudioPlay(myAuto,2,3000); //执行播放函数
当然你还可以改歌曲实现歌单循环播放哦