Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jPlayer 2.0 Elapsed/Remaining Time

I'm working with jPlayer 2.0

I've got it playing, pausing, etc...but how do I grab the elapsed/remaining time attributes from the jquery object? I've tried the event handlers and even provided HTML elements with the default selectors, but none of that appears to work.

Thanks in advance!

like image 982
El Lobo Negron Avatar asked Jun 16 '11 19:06

El Lobo Negron


1 Answers

I did it this way:

self.update_timer = function (event) {
    var status = event.jPlayer.status;
    $('.jtimer').text($.jPlayer.convertTime(status.duration - status.currentTime));
};


$('.jplayer')
    .jPlayer('setMedia', {
        mp3: mp3_link
     })
    .jPlayer('play')
    .bind($.jPlayer.event.timeupdate, self.update_timer);

The important is that timeupdate event sends status object with duration and currentTime properties that contain exactly what you need. The event is fired 4 times per second.

$.jPlayer.convertTime converts plain seconds (4225) into hours:minutes:seconds (01:10:25).

I don't know exactly if this was available in 2.0, but in jPlayer 2.1.0 that I use this is written in the docs.

like image 102
culebrón Avatar answered Nov 12 '22 23:11

culebrón