var song1 = $('#sound-1');
var song2 = $('#sound-2');
var audioArray = [song1, song2];
var i=0;
var lastPlayedFile = null;
$(".click").click(function(){
if(lastPlayedFile !== null) {
lastPlayedFile[0].currentTime = 0;
lastPlayedFile.trigger('pause');
}
if (i< audioArray.length){
lastPlayedFile = audioArray[i];
audioArray[i].trigger('play');
i++;
} else if (i>=audioArray.length){
i = 0;
lastPlayedFile = audioArray[0];
audioArray[i].trigger('play');
};
});这段代码不适用于我,我使用的是firefox web浏览器。这段代码有什么问题吗?
发布于 2018-06-18 19:17:26
<audio>标记,如here所示。浏览器将拾取第一个可识别的源:<audio controls> // browser tries to fetch horse.ogg first <source src="horse.ogg" type="audio/ogg"> // browser tries to fetch horse.mp3 if the above couldn't be recognized <source src="horse.mp3" type="audio/mpeg"> // if none files are valid the browser falls back with a message Your browser does not support the audio element. </audio>
lastPlayedFile[0].currentTime = 0;
确保在每个audioArray元素(song1和song2) )上都设置了currentTime属性
https://stackoverflow.com/questions/50888632
复制相似问题