jPlayer 2.0 Elapsed/Remaining Time
Asked Answered
W

1

8

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!

Woeful answered 16/6, 2011 at 19:28 Comment(0)
S
13

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.

Subsequent answered 4/9, 2011 at 12:6 Comment(1)
("Where should I ...") Wherever you need, just like $('element').click(...) handler can be defined anywhere. You may inline it: .bind($.lalala.timeupdate, function() { taram param });Montmartre

© 2022 - 2024 — McMap. All rights reserved.