如何“等待”?在jplayer中执行代码直到歌曲结束

how to "wait" to execute code until end of song in jplayer

本文关键字:代码 结束 执行 等待 jplayer 如何      更新时间:2023-09-26

我在jplayer中循环,但在播放歌曲时循环继续进行。如何才能在播放完歌曲后才开始下一个循环?这是一个自定义洗牌函数。这里是jplayer相关的javascript代码-它的工作,除了我需要循环只去下一个迭代后,每首歌播放完成:

var currentId = 0;
for (currentId = 0; currentId < numSongs + 1; currentId++) {
    $.ajax({
    ....      
        $(document).ready(function(){           
            $("#jquery_jplayer_1").jPlayer({            
                ready: function () {
                    $(this).jPlayer("setMedia", {
                    mp3: currentURL
                }).jPlayer("play"); 
           $(".adder").click(function() {
            $.get("...php?id=" + currentId);
       });
    },
   swfPath: "/js",
   supplied: "mp3"
    });
}

谢谢你的帮助。

这样的循环是不可能的,因为jPlayer方法会立即返回。如果您钩到ended事件,您可以在那里开始播放下一首歌曲。