-
Notifications
You must be signed in to change notification settings - Fork 7.5k
/
play-progress-bar.js
91 lines (79 loc) · 2.21 KB
/
play-progress-bar.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
/**
* @file play-progress-bar.js
*/
import Component from '../../component.js';
import {IS_IOS, IS_ANDROID} from '../../utils/browser.js';
import * as Fn from '../../utils/fn.js';
/** @import Player from '../../player' */
import './time-tooltip';
/**
* Used by {@link SeekBar} to display media playback progress as part of the
* {@link ProgressControl}.
*
* @extends Component
*/
class PlayProgressBar extends Component {
/**
* Creates an instance of this class.
*
* @param {Player} player
* The {@link Player} that this class should be attached to.
*
* @param {Object} [options]
* The key/value store of player options.
*/
constructor(player, options) {
super(player, options);
this.setIcon('circle');
this.update = Fn.throttle(Fn.bind_(this, this.update), Fn.UPDATE_REFRESH_INTERVAL);
}
/**
* Create the the DOM element for this class.
*
* @return {Element}
* The element that was created.
*/
createEl() {
return super.createEl('div', {
className: 'vjs-play-progress vjs-slider-bar'
}, {
'aria-hidden': 'true'
});
}
/**
* Enqueues updates to its own DOM as well as the DOM of its
* {@link TimeTooltip} child.
*
* @param {Object} seekBarRect
* The `ClientRect` for the {@link SeekBar} element.
*
* @param {number} seekBarPoint
* A number from 0 to 1, representing a horizontal reference point
* from the left edge of the {@link SeekBar}
*/
update(seekBarRect, seekBarPoint) {
const timeTooltip = this.getChild('timeTooltip');
if (!timeTooltip) {
return;
}
const time = (this.player_.scrubbing()) ?
this.player_.getCache().currentTime :
this.player_.currentTime();
timeTooltip.updateTime(seekBarRect, seekBarPoint, time);
}
}
/**
* Default options for {@link PlayProgressBar}.
*
* @type {Object}
* @private
*/
PlayProgressBar.prototype.options_ = {
children: []
};
// Time tooltips should not be added to a player on mobile devices
if (!IS_IOS && !IS_ANDROID) {
PlayProgressBar.prototype.options_.children.push('timeTooltip');
}
Component.registerComponent('PlayProgressBar', PlayProgressBar);
export default PlayProgressBar;