Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the duration of the song in JPlayer

Tags:

jquery

jplayer

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

Here i try to get the duration of the song. But it says "undefined". Other than this i tried to use the following, after calling the above function.

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

Then the duration became 0. How to get the real duration?

like image 572
dinesh707 Avatar asked Nov 02 '12 07:11

dinesh707


1 Answers

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");
    });
}
like image 167
dinesh707 Avatar answered Oct 10 '22 07:10

dinesh707