forked from mpvnet-player/mpv.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seek-show-position.js
37 lines (29 loc) · 995 Bytes
/
seek-show-position.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// When seeking displays position and duration like so: 01:10:00 / 01:20:00
// In input.conf set the input command prefix no-osd infront of the seek command.
function add_zero(val) {
val = Math.round(val);
return val > 9 ? "" + val : "0" + val;
}
function format(val) {
var sec = Math.round(val);
if (sec < 3600) {
if (sec < 0)
sec = 0;
pos_min_floor = Math.floor(sec / 60);
sec_rest = sec - pos_min_floor * 60;
return add_zero(pos_min_floor) + ":" + add_zero(sec_rest);
}
hours = Math.floor(sec / 3600);
sec %= 3600;
minutes = Math.floor(sec / 60);
seconds = sec % 60;
return add_zero(hours) + ":" + add_zero(minutes) + ":" + add_zero(seconds);
}
function on_seek(_) {
pos = mp.get_property_number("time-pos");
dur = mp.get_property_number("duration");
if (pos > dur)
pos = dur;
mp.commandv("show-text", format(pos) + " / " + format(dur));
}
mp.register_event("seek", on_seek);