-
Notifications
You must be signed in to change notification settings - Fork 7.5k
/
Copy pathskip-forward.js
80 lines (66 loc) · 2.28 KB
/
skip-forward.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
import Button from '../../button';
import Component from '../../component';
/**
* Button to skip forward a configurable amount of time
* through a video. Renders in the control bar.
*
* e.g. options: {controlBar: {skipButtons: forward: 5}}
*
* @extends Button
*/
class SkipForward extends Button {
constructor(player, options) {
super(player, options);
this.validOptions = [5, 10, 30];
this.skipTime = this.getSkipForwardTime();
if (this.skipTime && this.validOptions.includes(this.skipTime)) {
this.setIcon(`forward-${this.skipTime}`);
this.controlText(this.localize('Skip forward {1} seconds', [this.skipTime.toLocaleString(player.language())]));
this.show();
} else {
this.hide();
}
}
getSkipForwardTime() {
const playerOptions = this.options_.playerOptions;
return playerOptions.controlBar && playerOptions.controlBar.skipButtons && playerOptions.controlBar.skipButtons.forward;
}
buildCSSClass() {
return `vjs-skip-forward-${this.getSkipForwardTime()} ${super.buildCSSClass()}`;
}
/**
* On click, skips forward in the duration/seekable range by a configurable amount of seconds.
* If the time left in the duration/seekable range is less than the configured 'skip forward' time,
* skips to end of duration/seekable range.
*
* Handle a click on a `SkipForward` button
*
* @param {EventTarget~Event} event
* The `click` event that caused this function
* to be called
*/
handleClick(event) {
if (isNaN(this.player_.duration())) {
return;
}
const currentVideoTime = this.player_.currentTime();
const liveTracker = this.player_.liveTracker;
const duration = (liveTracker && liveTracker.isLive()) ? liveTracker.seekableEnd() : this.player_.duration();
let newTime;
if (currentVideoTime + this.skipTime <= duration) {
newTime = currentVideoTime + this.skipTime;
} else {
newTime = duration;
}
this.player_.currentTime(newTime);
}
/**
* Update control text on languagechange
*/
handleLanguagechange() {
this.controlText(this.localize('Skip forward {1} seconds', [this.skipTime]));
}
}
SkipForward.prototype.controlText_ = 'Skip Forward';
Component.registerComponent('SkipForward', SkipForward);
export default SkipForward;