jQuery调用一个函数来播放下一个音频文件



我找到了一个播放音频文件的函数(onclick(,她工作得很好

我想在当前结束时使用此功能播放下一个音频文件所以我回忆起onended内部的函数,下一个音频文件被播放,但它冻结并重复到无穷大,而不传递到下一个文件

var thissound = new Audio();
var currentKey;
function EvalSound(key)
{
if (currentKey !== key)
thissound.src = "media/audio/chapters/" + chapternum + "/" + key + ".mp3";
currentKey = key;
if (thissound.paused)
{
thissound.play();
}
else
{
thissound.pause();
thissound.currentTime = 0;
currentPlayer = thissound;
}
}
$(".audio").click(function(e) 
{
e.preventDefault();
var parentid = $(this).parent().parent().attr('id');     
var nextfile = parseInt(parentid)  + 1; 
EvalSound(parentid);
thissound.onended = function()
{
EvalSound(nextfile);
return false;
}; 
});

HTML(例如(

<li class="liste" id="1">
<p><img class="audio" src="images/default/buttons/play.png" alt="Play" title="Play" /></p>
<p>some text</p>
</li>
<li class="liste" id="2">
<p><img class="audio" src="images/default/buttons/play.png" alt="Play" title="Play" /></p>
<p>some text</p>
</li>
...
...

感谢您的帮助

我解决了它所以,我把";thisssound.onended=函数(("功能内部

thissound.onended = function()
{
var nextfile = parseInt(key)  + 1;
if($("#" + nextfile).length)
{
$(window).scrollTop($('#' + nextfile).offset().top);
EvalSound(nextfile);
}
}; 

最新更新