((typeof self !== 'undefined' ? self : this)["webpackJsonpcutting_mat_widgets"] = (typeof self !== 'undefined' ? self : this)["webpackJsonpcutting_mat_widgets"] || []).push([[3],{

/***/ 107:
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return SwitcherPlugin; });
/* harmony import */ var _babel_runtime_helpers_esm_inheritsLoose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(102);
/* harmony import */ var video_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(101);


var MenuItem = video_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"].getComponent("MenuItem");

var ResolutionMenuItem = /*#__PURE__*/function (_MenuItem) {
  Object(_babel_runtime_helpers_esm_inheritsLoose__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(ResolutionMenuItem, _MenuItem);

  function ResolutionMenuItem(player, options) {
    var _this;

    var label = options.label;
    options.label = label;
    options.selected = label === player.currentResolution().label;
    options.selectable = true;
    options.multiSelectable = false;
    _this = _MenuItem.call(this, player, options) || this;
    _this.label = label;

    _this.on(player, "resolutionchange", function (e) {
      return _this.update(e);
    });

    return _this;
  }

  var _proto = ResolutionMenuItem.prototype;

  _proto.handleClick = function handleClick(event) {
    _MenuItem.prototype.handleClick.call(this);

    this.player().currentResolution(this.label);
  };

  _proto.update = function update() {
    var selectd = this.label === this.player().currentResolution().label;
    this.selected(selectd);
  };

  return ResolutionMenuItem;
}(MenuItem);

ResolutionMenuItem.prototype.contentElType = "button";
video_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"].registerComponent("ResolutionMenuItem", ResolutionMenuItem);
var MenuButton = video_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"].getComponent("MenuButton");

var ResolutionMenuButton = /*#__PURE__*/function (_MenuButton) {
  Object(_babel_runtime_helpers_esm_inheritsLoose__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(ResolutionMenuButton, _MenuButton);

  function ResolutionMenuButton(player, options) {
    var _this2;

    _this2 = _MenuButton.call(this, player) || this;

    _this2.controlText("Quality");

    _this2.on(player, "loadstart", function (e) {
      return _this2.updateLabel(e);
    });

    _this2.on(player, "updateSources", function (e) {
      _this2.updateLabel(e);

      _this2.update();
    });

    return _this2;
  }

  var _proto2 = ResolutionMenuButton.prototype;

  _proto2.createEl = function createEl() {
    var el = _MenuButton.prototype.createEl.call(this);

    this.labelElId_ = "vjs-playback-rate-value-label-" + this.id_;
    this.labelEl_ = video_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"].dom.createEl("div", {
      className: "vjs-resolution-button-label",
      id: this.labelElId_,
      textContent: ""
    });
    el.appendChild(this.labelEl_);
    return el;
  };

  _proto2.dispose = function dispose() {
    _MenuButton.prototype.dispose.call(this);
  };

  _proto2.buildCSSClass = function buildCSSClass() {
    return "vjs-resolution-button " + _MenuButton.prototype.buildCSSClass.call(this);
  };

  _proto2.buildWrapperCSSClass = function buildWrapperCSSClass() {
    return "vjs-resolution-button " + _MenuButton.prototype.buildWrapperCSSClass.call(this);
  };

  _proto2.createItems = function createItems() {
    this.sources = this.player().groupedSrc;
    var items = [];
    var list = this.sources && this.sources.label || {};

    for (var key in list) {
      if (list.hasOwnProperty(key)) {
        items.push(new ResolutionMenuItem(this.player(), {
          label: key,
          src: list[key],
          selected: key === (this.currentSelection ? this.currentSelection.label : false)
        }));
      }
    }

    return items;
  };

  _proto2.updateLabel = function updateLabel() {
    this.currentSelection = this.player().currentResolution();
    this.labelEl_.textContent = this.currentSelection ? this.currentSelection.label : "";
  };

  return ResolutionMenuButton;
}(MenuButton);

video_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"].registerComponent("ResolutionMenuButton", ResolutionMenuButton);
var version = "0.0.6";
var plugin = "";
var videojs;

if (window.videojs) {
  videojs = window.videojs;
  console.warn("SwitcherPlugin:\u68C0\u6D4B\u5230window.videojs");
} else {
  videojs = video_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"];
}

var Plugin = videojs.getPlugin("plugin");

var SwitcherPlugin = /*#__PURE__*/function (_Plugin) {
  Object(_babel_runtime_helpers_esm_inheritsLoose__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(SwitcherPlugin, _Plugin);

  function SwitcherPlugin(player, options) {
    var _this3;

    if (options === void 0) {
      options = {};
    }

    _this3 = _Plugin.call(this, player, options) || this;

    player.updateSrc = function (src) {
      if (!Array.isArray(src) && src.length) {
        return player.src();
      }

      src = src.filter(function (source) {
        try {
          return player.canPlayType(source.type) !== "";
        } catch (e) {
          return true;
        }
      });
      this.currentSources = src.sort(compareResolutions);
      this.groupedSrc = bucketSources(this.currentSources);
      var chosen = chooseSrc(this.groupedSrc, this.currentSources);
      this.currentResolutionState = {
        label: chosen.label,
        sources: chosen.sources
      };
      player.trigger("updateSources");
      player.setSourcesSanitized(chosen.sources, chosen.label);
      player.trigger("resolutionchange");
      return player;
    };

    player.currentResolution = function (label) {
      if (label == null) {
        return this.currentResolutionState;
      }

      if (!this.groupedSrc || !this.groupedSrc.label || !this.groupedSrc.label[label]) {
        return;
      }

      var sources = this.groupedSrc.label[label];
      var currentTime = player.currentTime();
      var isPaused = player.paused();

      if (!isPaused && this.player().options_.bigPlayButton) {
        this.player().bigPlayButton.hide();
      }

      player.setSourcesSanitized(sources, label).one("loadeddata", function () {
        player.currentTime(currentTime);

        if (!isPaused) {
          player.play();
        }

        player.trigger("updateSources");
        player.trigger("resolutionchange");
      });
      return player;
    };

    player.setSourcesSanitized = function (sources, label) {
      this.currentResolutionState = {
        label: label,
        sources: sources
      };
      player.src(sources.map(function (src) {
        return {
          src: src.src,
          type: src.type,
          res: src.res
        };
      }));
      return player;
    };

    function compareResolutions(a, b) {
      if (!a.res || !b.res) {
        return 0;
      }

      return +b.res - +a.res;
    }

    function bucketSources(src) {
      var resolutions = {
        label: {},
        res: {},
        type: {}
      };
      src.map(function (source) {
        for (var key in resolutions) {
          if (resolutions[key][source[key]] == null) {
            resolutions[key][source[key]] = [];
          }

          resolutions[key][source[key]].push(source);
        }
      });
      return resolutions;
    }

    function chooseSrc(groupedSrc, src) {
      var selectedRes = options.default || "low";
      var selectedLabel = "";

      if (selectedRes === "high") {
        selectedRes = src[0].res;
        selectedLabel = src[0].label;
      } else if (selectedRes === "low" || !groupedSrc.res[selectedRes]) {
        selectedRes = src[src.length - 1].res;
        selectedLabel = src[src.length - 1].label;
      } else if (groupedSrc.res[selectedRes]) {
        selectedLabel = groupedSrc.res[selectedRes][0].label;
      }

      return {
        res: selectedRes,
        label: selectedLabel,
        sources: groupedSrc.res[selectedRes]
      };
    }

    var menuButton = new ResolutionMenuButton(player);
    player.controlBar.el_.insertBefore(menuButton.el_, player.controlBar.getChild("fullscreenToggle").el_);

    if (player.options_.sources.length > 1) {
      player.updateSrc(player.options_.sources);
    }

    return _this3;
  }

  var _proto3 = SwitcherPlugin.prototype;

  _proto3.dispose = function dispose() {
    _Plugin.prototype.dispose.call(this);
  };

  return SwitcherPlugin;
}(Plugin);

SwitcherPlugin.defaultState = {};
SwitcherPlugin.VERSION = version;
videojs.registerPlugin("SwitcherPlugin", SwitcherPlugin);


/***/ })

}]);