-
Notifications
You must be signed in to change notification settings - Fork 7.5k
/
audio-track-button.js
85 lines (73 loc) · 2.07 KB
/
audio-track-button.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
/**
* @file audio-track-button.js
*/
import TrackButton from '../track-button.js';
import Component from '../../component.js';
import AudioTrackMenuItem from './audio-track-menu-item.js';
/**
* The base class for buttons that toggle specific {@link AudioTrack} types.
*
* @extends TrackButton
*/
class AudioTrackButton extends TrackButton {
/**
* Creates an instance of this class.
*
* @param {Player} player
* The `Player` that this class should be attached to.
*
* @param {Object} [options={}]
* The key/value store of player options.
*/
constructor(player, options = {}) {
options.tracks = player.audioTracks();
super(player, options);
this.setIcon('audio');
}
/**
* Builds the default DOM `className`.
*
* @return {string}
* The DOM `className` for this object.
*/
buildCSSClass() {
return `vjs-audio-button ${super.buildCSSClass()}`;
}
buildWrapperCSSClass() {
return `vjs-audio-button ${super.buildWrapperCSSClass()}`;
}
/**
* Create a menu item for each audio track
*
* @param {AudioTrackMenuItem[]} [items=[]]
* An array of existing menu items to use.
*
* @return {AudioTrackMenuItem[]}
* An array of menu items
*/
createItems(items = []) {
// if there's only one audio track, there no point in showing it
this.hideThreshold_ = 1;
const tracks = this.player_.audioTracks();
for (let i = 0; i < tracks.length; i++) {
const track = tracks[i];
items.push(new AudioTrackMenuItem(this.player_, {
track,
// MenuItem is selectable
selectable: true,
// MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
multiSelectable: false
}));
}
return items;
}
}
/**
* The text that should display over the `AudioTrackButton`s controls. Added for localization.
*
* @type {string}
* @protected
*/
AudioTrackButton.prototype.controlText_ = 'Audio Track';
Component.registerComponent('AudioTrackButton', AudioTrackButton);
export default AudioTrackButton;