3 exports.__esModule = true;
5 var _trackList = require('./track-list');
7 var _trackList2 = _interopRequireDefault(_trackList);
9 var _browser = require('../utils/browser.js');
11 var browser = _interopRequireWildcard(_browser);
13 var _document = require('global/document');
15 var _document2 = _interopRequireDefault(_document);
17 function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
19 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
21 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
25 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
26 * @file audio-track-list.js
31 * Anywhere we call this function we diverge from the spec
32 * as we only support one enabled audiotrack at a time
34 * @param {AudioTrackList} list
37 * @param {AudioTrack} track
42 var disableOthers = function disableOthers(list, track) {
43 for (var i = 0; i < list.length; i++) {
44 if (track.id === list[i].id) {
47 // another audio track is enabled, disable it
48 list[i].enabled = false;
53 * The current list of {@link AudioTrack} for a media file.
55 * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotracklist}
59 var AudioTrackList = function (_TrackList) {
60 _inherits(AudioTrackList, _TrackList);
63 * Create an instance of this class.
65 * @param {AudioTrack[]} [tracks=[]]
66 * A list of `AudioTrack` to instantiate the list with.
68 function AudioTrackList() {
71 var tracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
73 _classCallCheck(this, AudioTrackList);
77 // make sure only 1 track is enabled
78 // sorted from last index to first index
79 for (var i = tracks.length - 1; i >= 0; i--) {
80 if (tracks[i].enabled) {
81 disableOthers(tracks, tracks[i]);
86 // IE8 forces us to implement inheritance ourselves
87 // as it does not support Object.defineProperty properly
89 list = _document2['default'].createElement('custom');
90 for (var prop in _trackList2['default'].prototype) {
91 if (prop !== 'constructor') {
92 list[prop] = _trackList2['default'].prototype[prop];
95 for (var _prop in AudioTrackList.prototype) {
96 if (_prop !== 'constructor') {
97 list[_prop] = AudioTrackList.prototype[_prop];
102 list = (_this = _possibleConstructorReturn(this, _TrackList.call(this, tracks, list)), _this);
103 list.changing_ = false;
105 return _ret = list, _possibleConstructorReturn(_this, _ret);
109 * Add an {@link AudioTrack} to the `AudioTrackList`.
111 * @param {AudioTrack} track
112 * The AudioTrack to add to the list
114 * @fires Track#addtrack
119 AudioTrackList.prototype.addTrack_ = function addTrack_(track) {
123 disableOthers(this, track);
126 _TrackList.prototype.addTrack_.call(this, track);
127 // native tracks don't have this
128 if (!track.addEventListener) {
133 * @listens AudioTrack#enabledchange
134 * @fires TrackList#change
136 track.addEventListener('enabledchange', function () {
137 // when we are disabling other tracks (since we don't support
138 // more than one track at a time) we will set changing_
139 // to true so that we don't trigger additional change events
140 if (_this2.changing_) {
143 _this2.changing_ = true;
144 disableOthers(_this2, track);
145 _this2.changing_ = false;
146 _this2.trigger('change');
151 * Add an {@link AudioTrack} to the `AudioTrackList`.
153 * @param {AudioTrack} track
154 * The AudioTrack to add to the list
156 * @fires Track#addtrack
160 AudioTrackList.prototype.addTrack = function addTrack(track) {
161 this.addTrack_(track);
165 * Remove an {@link AudioTrack} from the `AudioTrackList`.
167 * @param {AudioTrack} track
168 * The AudioTrack to remove from the list
170 * @fires Track#removetrack
174 AudioTrackList.prototype.removeTrack = function removeTrack(track) {
175 _TrackList.prototype.removeTrack_.call(this, track);
178 return AudioTrackList;
179 }(_trackList2['default']);
181 exports['default'] = AudioTrackList;