text: /* eslint-disable */
  import videojs from 'video.js';
  
  function _extends() {
    _extends = Object.assign || function (target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i];
  
        for (var key in source) {
          if (Object.prototype.hasOwnProperty.call(source, key)) {
            target[key] = source[key];
          }
        }
      }
  
      return target;
    };
  
    return _extends.apply(this, arguments);
  }
  
  function _inheritsLoose(subClass, superClass) {
    subClass.prototype = Object.create(superClass.prototype);
    subClass.prototype.constructor = subClass;
    subClass.__proto__ = superClass;
  }
  
  function _assertThisInitialized(self) {
    if (self === void 0) {
      throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
    }
  
    return self;
  }
  
  var SettingOptionItem = videojs.getComponent('SettingOptionItem');
  
  var AudioTrackSettingItem =
  /*#__PURE__*/
  function (_SettingOptionItem) {
    _inheritsLoose(AudioTrackSettingItem, _SettingOptionItem);
  
    function AudioTrackSettingItem(player, options) {
      var _this;
  
      _this = _SettingOptionItem.call(this, player, _extends({}, options, {
        name: 'AudioTrackSettingItem',
        label: 'Audio',
        icon: 'vjs-icon-audiotrack'
      })) || this;
  
      _this.addClass('vjs-setting-audio');
  
      var timeout;
  
      var onHlsUsageEvent = function onHlsUsageEvent(evt) {
        if (evt.name === 'hls-audio-change') {
          clearTimeout(timeout);
          timeout = setTimeout(_this.handleAudioChangeEvent.bind(_assertThisInitialized(_this)), 10);
        } else if (evt.name === 'hls-alternate-audio') {
          _this.onAlternateAudio();
        }
      };
  
      player.ready(function () {
        // show when alternate audio detected
        player.tech_.on('usage', onHlsUsageEvent);
      }); // unbind the callback on player dispose
  
      player.on('dispose', function () {
        player.tech_.off('usage', onHlsUsageEvent);
      });
      player.on('audiochange', function (_, _ref) {
        var index = _ref.index;
  
        _this.select(index);
  
        _this.update(index);
      }); // hide when new source set
  
      player.on('loadstart', function () {
        _this.hide();
      });
      return _this;
    }
  
    var _proto = AudioTrackSettingItem.prototype;
  
    _proto.onChange = function onChange(_ref2) {
      var value = _ref2.value;
      this.player_.audio().pick(value);
    };
  
    _proto.onAlternateAudio = function onAlternateAudio() {
      var _this2 = this;
  
      var audioTracks = this.player_.audio().values();
      var audioEntries = audioTracks.map(function (track, index) {
        var id = track.id,
            kind = track.kind,
            label = track.label,
            language = track.language; // label and value are necessary attributes
  
        return {
          label: _this2.localize(label),
          value: index,
          id: id,
          kind: kind,
          language: language,
          index: index,
          track: track
        };
      });
      this.player_.trigger('before-audio-setup', audioEntries);
      this.setEntries(audioEntries);
      this.show();
      this.player_.trigger('audio', audioEntries);
    };
  
    _proto.handleAudioChangeEvent = function handleAudioChangeEvent() {
      var _this3 = this;
  
      var audioTracks = this.player_.audio().values();
      var currentEntry = audioTracks.reduce(function (acc, track, index) {
        if (track.enabled) {
          acc = _this3.entries[index];
        }
  
        return acc;
      }, {});
      this.player_.trigger('audiochange', currentEntry);
    };
  
    return AudioTrackSettingItem;
  }(SettingOptionItem);
  
  videojs.getComponent('SettingMenuButton').prototype.options_.entries.push('AudioTrackSettingItem');
  videojs.registerComponent('AudioTrackSettingItem', AudioTrackSettingItem);
  
  var audio =
  /*#__PURE__*/
  function (_videojs$getPlugin) {
    _inheritsLoose(audio, _videojs$getPlugin);
  
    function audio(player, options) {
      var _this;
  
      if (options === void 0) {
        options = {};
      }
  
      _this = _videojs$getPlugin.call(this, player, options) || this;
      _this.track = _this.values().find(function (track) {
        return track.enabled;
      }); // I am worried about audio changed by other factor
      // So also listen on `audiochange` and update the value
  
      player.on('audiochange', function (_, _ref) {
        var index = _ref.index;
        _this.track = _this.values()[index];
      });
      return _this;
    }
  
    var _proto = audio.prototype;
  
    _proto.values = function values() {
      var tracks = this.player.audioTracks();
      var result = [];
  
      for (var i = 0; i < tracks.length; i++) {
        result.push(tracks[i]);
      }
  
      return result;
    };
  
    _proto.pick = function pick(index) {
      var values = this.values();
      var newAudio = values[index];
  
      if (newAudio) {
        this.track.enabled = false;
        this.track = newAudio;
        newAudio.enabled = true;
      }
    };
  
    return audio;
  }(videojs.getPlugin('plugin'));
  
  videojs.registerPlugin('audio', audio);
  //# sourceMappingURL=audio-track.es.js.map
  