无法绑定到document.ready上的JPlayer事件

时间:2013-02-14 13:18:44

标签: javascript jquery google-chrome audio jplayer

我正在使用jplayer在网页上播放音频,当页面加载时,检查器和播放器都可以正常加载,但绑定功能不起作用。如果我稍后从控制台调用它然后它工作正常。

$(document).ready(function(){
    myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
        { mp3: flatplaylist[0] },
        { supplied: "mp3", }
    );
    $("#jplayer_inspector").jPlayerInspector({jPlayer:$("#jquery_jplayer_1")});
    //does not work from here, but will work if I put this in the console.
    $(myCirclePlayer.audio).bind('ended',function (){ playNextFile(); }); 
});

1 个答案:

答案 0 :(得分:3)

这是我的最终代码,工作正常。

var PlayerID = "#jquery_jplayer_1";
$(window).ready(function(){
    myCirclePlayer = new CirclePlayer(PlayerID,{mp3: 'audio/'+mypl.playlist[0]},{supplied: "mp3",});
    $("#jplayer_inspector").jPlayerInspector({jPlayer:$("#jquery_jplayer_1")});
    $(PlayerID).bind($.jPlayer.event.ended, function (){ playNextFile(); });
});