- 1 :
import {VideoTrackKind} from './track-enums';
- 2 :
import Track from './track';
- 3 :
import merge from '../utils/merge-options';
- 4 :
- 5 :
/**
- 6 :
* A representation of a single `VideoTrack`.
- 7 :
*
- 8 :
* @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#videotrack}
- 9 :
* @extends Track
- 10 :
*/
- 11 :
class VideoTrack extends Track {
- 12 :
- 13 :
/**
- 14 :
* Create an instance of this class.
- 15 :
*
- 16 :
* @param {Object} [options={}]
- 17 :
* Object of option names and values
- 18 :
*
- 19 :
* @param {string} [options.kind='']
- 20 :
* A valid {@link VideoTrack~Kind}
- 21 :
*
- 22 :
* @param {string} [options.id='vjs_track_' + Guid.newGUID()]
- 23 :
* A unique id for this AudioTrack.
- 24 :
*
- 25 :
* @param {string} [options.label='']
- 26 :
* The menu label for this track.
- 27 :
*
- 28 :
* @param {string} [options.language='']
- 29 :
* A valid two character language code.
- 30 :
*
- 31 :
* @param {boolean} [options.selected]
- 32 :
* If this track is the one that is currently playing.
- 33 :
*/
- 34 :
constructor(options = {}) {
- 35 :
const settings = merge(options, {
- 36 :
kind: VideoTrackKind[options.kind] || ''
- 37 :
});
- 38 :
- 39 :
super(settings);
- 40 :
- 41 :
let selected = false;
- 42 :
- 43 :
/**
- 44 :
* @memberof VideoTrack
- 45 :
* @member {boolean} selected
- 46 :
* If this `VideoTrack` is selected or not. When setting this will
- 47 :
* fire {@link VideoTrack#selectedchange} if the state of selected changed.
- 48 :
* @instance
- 49 :
*
- 50 :
* @fires VideoTrack#selectedchange
- 51 :
*/
- 52 :
Object.defineProperty(this, 'selected', {
- 53 :
get() {
- 54 :
return selected;
- 55 :
},
- 56 :
set(newSelected) {
- 57 :
// an invalid or unchanged value
- 58 :
if (typeof newSelected !== 'boolean' || newSelected === selected) {
- 59 :
return;
- 60 :
}
- 61 :
selected = newSelected;
- 62 :
- 63 :
/**
- 64 :
* An event that fires when selected changes on this track. This allows
- 65 :
* the VideoTrackList that holds this track to act accordingly.
- 66 :
*
- 67 :
* > Note: This is not part of the spec! Native tracks will do
- 68 :
* this internally without an event.
- 69 :
*
- 70 :
* @event VideoTrack#selectedchange
- 71 :
* @type {EventTarget~Event}
- 72 :
*/
- 73 :
this.trigger('selectedchange');
- 74 :
}
- 75 :
});
- 76 :
- 77 :
// if the user sets this track to selected then
- 78 :
// set selected to that true value otherwise
- 79 :
// we keep it false
- 80 :
if (settings.selected) {
- 81 :
this.selected = settings.selected;
- 82 :
}
- 83 :
}
- 84 :
}
- 85 :
- 86 :
export default VideoTrack;