loader.js 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _component = require('../component.js');
  4. var _component2 = _interopRequireDefault(_component);
  5. var _tech = require('./tech.js');
  6. var _tech2 = _interopRequireDefault(_tech);
  7. var _toTitleCase = require('../utils/to-title-case.js');
  8. var _toTitleCase2 = _interopRequireDefault(_toTitleCase);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  10. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11. 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; }
  12. 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; } /**
  13. * @file loader.js
  14. */
  15. /**
  16. * The `MediaLoader` is the `Component` that decides which playback technology to load
  17. * when a player is initialized.
  18. *
  19. * @extends Component
  20. */
  21. var MediaLoader = function (_Component) {
  22. _inherits(MediaLoader, _Component);
  23. /**
  24. * Create an instance of this class.
  25. *
  26. * @param {Player} player
  27. * The `Player` that this class should attach to.
  28. *
  29. * @param {Object} [options]
  30. * The key/value stroe of player options.
  31. *
  32. * @param {Component~ReadyCallback} [ready]
  33. * The function that is run when this component is ready.
  34. */
  35. function MediaLoader(player, options, ready) {
  36. _classCallCheck(this, MediaLoader);
  37. // If there are no sources when the player is initialized,
  38. // load the first supported playback technology.
  39. var _this = _possibleConstructorReturn(this, _Component.call(this, player, options, ready));
  40. if (!options.playerOptions.sources || options.playerOptions.sources.length === 0) {
  41. for (var i = 0, j = options.playerOptions.techOrder; i < j.length; i++) {
  42. var techName = (0, _toTitleCase2['default'])(j[i]);
  43. var tech = _tech2['default'].getTech(techName);
  44. // Support old behavior of techs being registered as components.
  45. // Remove once that deprecated behavior is removed.
  46. if (!techName) {
  47. tech = _component2['default'].getComponent(techName);
  48. }
  49. // Check if the browser supports this technology
  50. if (tech && tech.isSupported()) {
  51. player.loadTech_(techName);
  52. break;
  53. }
  54. }
  55. } else {
  56. // Loop through playback technologies (HTML5, Flash) and check for support.
  57. // Then load the best source.
  58. // A few assumptions here:
  59. // All playback technologies respect preload false.
  60. player.src(options.playerOptions.sources);
  61. }
  62. return _this;
  63. }
  64. return MediaLoader;
  65. }(_component2['default']);
  66. _component2['default'].registerComponent('MediaLoader', MediaLoader);
  67. exports['default'] = MediaLoader;