我在页面上有两个音频元素:
<audio id="voice1" class="voice1 voice" controls>
<source src="1.mp3" type="audio/mpeg">
</audio>
<audio id="voice1" class="voice2 voice" controls>
<source src="2.mp3" type="audio/mpeg">
</audio>
我想播放第一个,暂停5秒,播放第二个,再暂停5秒,然后重复整个过程固定次数。
jQuery(document).ready(function(){
for (j = 0; j < 100; ++j) {
var audioArray = document.getElementsByClassName('voice');
var i = 0;
audioArray[i].play();
for (i = 0; i < audioArray.length - 1; ++i) {
audioArray[i].addEventListener('ended', function(e){
// pause here for 5 seconds
var currentSong = e.target;
var next = $(currentSong).nextAll('audio');
if (next.length) $(next[0]).trigger('play');
});
}
});
我已经尝试过setInterval和setTimeout,但我无法让这个暂停工作。我考虑过播放一个安静的mp3文件5秒,但这看起来很愚蠢。任何人都可以推荐合适的方法吗?