[英]I need to play next song when click on on-click button
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浏览器。 这段代码有什么问题吗?
请确保您使用的是正确<audio>
和所示的标签在这里 。 浏览器将选择第一个可识别的源:
<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>
还请确保您尝试访问的文件确实存在。 我尝试找到它们,但是得到了404响应。
此外,这行代码不会执行任何操作:
lastPlayedFile[0].currentTime = 0;
请确保你有一个currentTime
属性集在每个的audioArray
元素( song1
和song2
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.