jPlayer 2.0 Elapsed/Remaining Time

2019-04-26 19:01发布

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!

1条回答
再贱就再见
2楼-- · 2019-04-26 19:56

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.

查看更多
登录 后发表回答