简体   繁体   English

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

[英]Cannot bind to JPlayer event on document.ready

I'm using jplayer for playing audio on a webpage, and when the page loads, the inspector and the player get loaded fine, but the bind function does not work. 我正在使用jplayer在网页上播放音频,并且当页面加载时,检查器和播放器可以很好地加载,但是bind函数不起作用。 If I call it later from the console then it works fine. 如果我稍后从控制台调用它,那么它将正常工作。

$(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(); }); 
});

Here's my final code, which works fine. 这是我的最终代码,可以正常工作。

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(); });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM