5
function intilizePlayer(){ 
    $("#jquery_jplayer_1").jPlayer({
        ready: function (event) {
            $(this).jPlayer("setMedia", {
                oga:song
            });
            songDuration = $(this).jPlayer.status.duration;
        },
        ended: function (event) {
                $(this).jPlayer("play");
        },
        swfPath: "swf",
        supplied: "oga"
    }).bind($.jPlayer.event.play, function() {
        $(this).jPlayer("pauseOthers");
    });
}

在这里,我尝试获取歌曲的持续时间。但它说“未定义”。除此之外,我在调用上述函数后尝试使用以下内容。

var duration = $("#jquery_jplayer_1").data("jPlayer").status.duration;

然后持续时间变为0。如何获得真正的持续时间?

4

1 回答 1

7
function intilizePlayer(){ 
    $("#jquery_jplayer_1").jPlayer({
        ready: function (event) {
            $(this).jPlayer("setMedia", {
                oga:song
            });
        },
        ended: function (event) {
                $(this).jPlayer("play");
        },
        loadeddata: function(event){ // calls after setting the song duration
            songDuration = event.jPlayer.status.duration;
        },
        swfPath: "swf",
        supplied: "oga"
    }).bind($.jPlayer.event.play, function() {
        $(this).jPlayer("pauseOthers");
    });
}
于 2012-11-02T08:02:31.597 回答