-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvideojs.timecode.js
98 lines (72 loc) · 2.42 KB
/
videojs.timecode.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Video.js Timecode
* Show timecodes in broadcast style hh:mm:ss:ff
* Requires jQuery
*
* Copyright (c) 2015 gasvard
*/
(function(window, videojs) {
'use strict';
window['videojs_timecode'] = { version: "0.0.1" };
var timecode = function(options) {
var player = this;
var def_options = {
timeFormat: 'PAL'
};
options = options || {};
var timeFormat = options.timeFormat || def_options.timeFormat;
var videoWrapper = $(this.el());
var timeEl = videoWrapper.find('.vjs-current-time-display');
//making space for longer timecode
timeEl.parent().css("width", "6em");
var durationEl = videoWrapper.find('.vjs-duration-display');
var timeUpdate = function (event) {
timeEl.html(MillToTimecode(player.currentTime(), timeFormat));
durationEl.html(MillToTimecode(player.duration(), timeFormat));
};
player.on('timeupdate', timeUpdate);
return this;
};
videojs.plugin('timecode', timecode);
})(window, window.videojs);
//Converts time in seconds to a broadcast timecode
//timeFormat: 'PAL', 'PALp', 'NTSC', 'STANDARD'
function MillToTimecode(seconds, TimeFormat) {
//alert(milliseconds);
var h = Math.floor(seconds / 3600);
seconds = seconds - h * 3600;
var m = Math.floor(seconds / 60);
seconds = seconds - m * 60;
var s = Math.floor(seconds);
seconds = seconds - s;
if (TimeFormat == 'PAL') {
var f = Math.floor((seconds * 1000) / 40);
}
else if (TimeFormat == 'NTSC') {
var f = Math.floor((seconds * 30000) / 1001);
}
else if (TimeFormat == 'PALp') {
var f = Math.floor((seconds * 1000) / 20);
}
else if (TimeFormat == 'NTSCp') {
var f = Math.floor((seconds * 60000) / 1001);
}
else if (TimeFormat == 'STANDARD') {
var f = Math.floor(seconds * 1000);
}
else {
// assume frame rate is given in numeric form
var f = Math.floor(seconds * TimeFormat);
}
// Check if we need to show hours
h = (h < 10) ? ("0" + h) + ":" : h + ":";
// If hours are showing, we may need to add a leading zero.
// Always show at least one digit of minutes.
m = (((h) && m < 10) ? "0" + m : m) + ":";
// Check if leading zero is need for seconds
s = ((s < 10) ? "0" + s : s) + ":";
f = (f < 10) ? "0" + f : f;
if (TimeFormat == 'STANDARD')
f = (f < 100) ? "0" + f : f;
return h + m + s + f;
}