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