summaryrefslogtreecommitdiff
path: root/javascript/videojs/src/js/control-bar/audio-track-controls/audio-track-button.js
diff options
context:
space:
mode:
Diffstat (limited to 'javascript/videojs/src/js/control-bar/audio-track-controls/audio-track-button.js')
-rw-r--r--javascript/videojs/src/js/control-bar/audio-track-controls/audio-track-button.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/javascript/videojs/src/js/control-bar/audio-track-controls/audio-track-button.js b/javascript/videojs/src/js/control-bar/audio-track-controls/audio-track-button.js
new file mode 100644
index 0000000..80eb7f0
--- /dev/null
+++ b/javascript/videojs/src/js/control-bar/audio-track-controls/audio-track-button.js
@@ -0,0 +1,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;