绍兴公厕前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1454 lines
38 KiB

3 years ago
  1. /**
  2. * videojs-flash
  3. * @version 2.2.1
  4. * @copyright 2019 Brightcove, Inc.
  5. * @license Apache-2.0
  6. */
  7. (function (global, factory) {
  8. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('video.js')) :
  9. typeof define === 'function' && define.amd ? define(['video.js'], factory) :
  10. (global.videojsFlash = factory(global.videojs));
  11. }(this, (function (videojs) { 'use strict';
  12. videojs = videojs && videojs.hasOwnProperty('default') ? videojs['default'] : videojs;
  13. var version = "5.4.2";
  14. var version$1 = "2.2.1";
  15. /**
  16. * @file flash-rtmp.js
  17. * @module flash-rtmp
  18. */
  19. /**
  20. * Add RTMP properties to the {@link Flash} Tech.
  21. *
  22. * @param {Flash} Flash
  23. * The flash tech class.
  24. *
  25. * @mixin FlashRtmpDecorator
  26. *
  27. * @return {Flash}
  28. * The flash tech with RTMP properties added.
  29. */
  30. function FlashRtmpDecorator(Flash) {
  31. Flash.streamingFormats = {
  32. 'rtmp/mp4': 'MP4',
  33. 'rtmp/flv': 'FLV'
  34. };
  35. /**
  36. * Join connection and stream with an ampersand.
  37. *
  38. * @param {string} connection
  39. * The connection string.
  40. *
  41. * @param {string} stream
  42. * The stream string.
  43. *
  44. * @return {string}
  45. * The connection and stream joined with an `&` character
  46. */
  47. Flash.streamFromParts = function (connection, stream) {
  48. return connection + '&' + stream;
  49. };
  50. /**
  51. * The flash parts object that contains connection and stream info.
  52. *
  53. * @typedef {Object} Flash~PartsObject
  54. *
  55. * @property {string} connection
  56. * The connection string of a source, defaults to an empty string.
  57. *
  58. * @property {string} stream
  59. * The stream string of the source, defaults to an empty string.
  60. */
  61. /**
  62. * Convert a source url into a stream and connection parts.
  63. *
  64. * @param {string} src
  65. * the source url
  66. *
  67. * @return {Flash~PartsObject}
  68. * The parts object that contains a connection and a stream
  69. */
  70. Flash.streamToParts = function (src) {
  71. var parts = {
  72. connection: '',
  73. stream: ''
  74. };
  75. if (!src) {
  76. return parts;
  77. }
  78. // Look for the normal URL separator we expect, '&'.
  79. // If found, we split the URL into two pieces around the
  80. // first '&'.
  81. var connEnd = src.search(/&(?![\w-]+=)/);
  82. var streamBegin = void 0;
  83. if (connEnd !== -1) {
  84. streamBegin = connEnd + 1;
  85. } else {
  86. // If there's not a '&', we use the last '/' as the delimiter.
  87. connEnd = streamBegin = src.lastIndexOf('/') + 1;
  88. if (connEnd === 0) {
  89. // really, there's not a '/'?
  90. connEnd = streamBegin = src.length;
  91. }
  92. }
  93. parts.connection = src.substring(0, connEnd);
  94. parts.stream = src.substring(streamBegin, src.length);
  95. return parts;
  96. };
  97. /**
  98. * Check if the source type is a streaming type.
  99. *
  100. * @param {string} srcType
  101. * The mime type to check.
  102. *
  103. * @return {boolean}
  104. * - True if the source type is a streaming type.
  105. * - False if the source type is not a streaming type.
  106. */
  107. Flash.isStreamingType = function (srcType) {
  108. return srcType in Flash.streamingFormats;
  109. };
  110. // RTMP has four variations, any string starting
  111. // with one of these protocols should be valid
  112. /**
  113. * Regular expression used to check if the source is an rtmp source.
  114. *
  115. * @property {RegExp} Flash.RTMP_RE
  116. */
  117. Flash.RTMP_RE = /^rtmp[set]?:\/\//i;
  118. /**
  119. * Check if the source itself is a streaming type.
  120. *
  121. * @param {string} src
  122. * The url to the source.
  123. *
  124. * @return {boolean}
  125. * - True if the source url indicates that the source is streaming.
  126. * - False if the shource url indicates that the source url is not streaming.
  127. */
  128. Flash.isStreamingSrc = function (src) {
  129. return Flash.RTMP_RE.test(src);
  130. };
  131. /**
  132. * A source handler for RTMP urls
  133. * @type {Object}
  134. */
  135. Flash.rtmpSourceHandler = {};
  136. /**
  137. * Check if Flash can play the given mime type.
  138. *
  139. * @param {string} type
  140. * The mime type to check
  141. *
  142. * @return {string}
  143. * 'maybe', or '' (empty string)
  144. */
  145. Flash.rtmpSourceHandler.canPlayType = function (type) {
  146. if (Flash.isStreamingType(type)) {
  147. return 'maybe';
  148. }
  149. return '';
  150. };
  151. /**
  152. * Check if Flash can handle the source natively
  153. *
  154. * @param {Object} source
  155. * The source object
  156. *
  157. * @param {Object} [options]
  158. * The options passed to the tech
  159. *
  160. * @return {string}
  161. * 'maybe', or '' (empty string)
  162. */
  163. Flash.rtmpSourceHandler.canHandleSource = function (source, options) {
  164. var can = Flash.rtmpSourceHandler.canPlayType(source.type);
  165. if (can) {
  166. return can;
  167. }
  168. if (Flash.isStreamingSrc(source.src)) {
  169. return 'maybe';
  170. }
  171. return '';
  172. };
  173. /**
  174. * Pass the source to the flash object.
  175. *
  176. * @param {Object} source
  177. * The source object
  178. *
  179. * @param {Flash} tech
  180. * The instance of the Flash tech
  181. *
  182. * @param {Object} [options]
  183. * The options to pass to the source
  184. */
  185. Flash.rtmpSourceHandler.handleSource = function (source, tech, options) {
  186. var srcParts = Flash.streamToParts(source.src);
  187. tech.setRtmpConnection(srcParts.connection);
  188. tech.setRtmpStream(srcParts.stream);
  189. };
  190. // Register the native source handler
  191. Flash.registerSourceHandler(Flash.rtmpSourceHandler);
  192. return Flash;
  193. }
  194. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  195. var win;
  196. if (typeof window !== "undefined") {
  197. win = window;
  198. } else if (typeof commonjsGlobal !== "undefined") {
  199. win = commonjsGlobal;
  200. } else if (typeof self !== "undefined"){
  201. win = self;
  202. } else {
  203. win = {};
  204. }
  205. var window_1 = win;
  206. var classCallCheck = function (instance, Constructor) {
  207. if (!(instance instanceof Constructor)) {
  208. throw new TypeError("Cannot call a class as a function");
  209. }
  210. };
  211. var inherits = function (subClass, superClass) {
  212. if (typeof superClass !== "function" && superClass !== null) {
  213. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  214. }
  215. subClass.prototype = Object.create(superClass && superClass.prototype, {
  216. constructor: {
  217. value: subClass,
  218. enumerable: false,
  219. writable: true,
  220. configurable: true
  221. }
  222. });
  223. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  224. };
  225. var possibleConstructorReturn = function (self, call) {
  226. if (!self) {
  227. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  228. }
  229. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  230. };
  231. /**
  232. * @file flash.js
  233. * VideoJS-SWF - Custom Flash Player with HTML5-ish API
  234. * https://github.com/zencoder/video-js-swf
  235. * Not using setupTriggers. Using global onEvent func to distribute events
  236. */
  237. var Tech = videojs.getComponent('Tech');
  238. var Dom = videojs.dom;
  239. var Url = videojs.url;
  240. var createTimeRange = videojs.createTimeRange;
  241. var mergeOptions = videojs.mergeOptions;
  242. var navigator = window_1 && window_1.navigator || {};
  243. /**
  244. * Flash Media Controller - Wrapper for Flash Media API
  245. *
  246. * @mixes FlashRtmpDecorator
  247. * @mixes Tech~SouceHandlerAdditions
  248. * @extends Tech
  249. */
  250. var Flash = function (_Tech) {
  251. inherits(Flash, _Tech);
  252. /**
  253. * Create an instance of this Tech.
  254. *
  255. * @param {Object} [options]
  256. * The key/value store of player options.
  257. *
  258. * @param {Component~ReadyCallback} ready
  259. * Callback function to call when the `Flash` Tech is ready.
  260. */
  261. function Flash(options, ready) {
  262. classCallCheck(this, Flash);
  263. // Set the source when ready
  264. var _this = possibleConstructorReturn(this, _Tech.call(this, options, ready));
  265. if (options.source) {
  266. _this.ready(function () {
  267. this.setSource(options.source);
  268. }, true);
  269. }
  270. // Having issues with Flash reloading on certain page actions
  271. // (hide/resize/fullscreen) in certain browsers
  272. // This allows resetting the playhead when we catch the reload
  273. if (options.startTime) {
  274. _this.ready(function () {
  275. this.load();
  276. this.play();
  277. this.currentTime(options.startTime);
  278. }, true);
  279. }
  280. // Add global window functions that the swf expects
  281. // A 4.x workflow we weren't able to solve for in 5.0
  282. // because of the need to hard code these functions
  283. // into the swf for security reasons
  284. window_1.videojs = window_1.videojs || {};
  285. window_1.videojs.Flash = window_1.videojs.Flash || {};
  286. window_1.videojs.Flash.onReady = Flash.onReady;
  287. window_1.videojs.Flash.onEvent = Flash.onEvent;
  288. window_1.videojs.Flash.onError = Flash.onError;
  289. _this.on('seeked', function () {
  290. this.lastSeekTarget_ = undefined;
  291. });
  292. return _this;
  293. }
  294. /**
  295. * Create the `Flash` Tech's DOM element.
  296. *
  297. * @return {Element}
  298. * The element that gets created.
  299. */
  300. Flash.prototype.createEl = function createEl() {
  301. var options = this.options_;
  302. // If video.js is hosted locally you should also set the location
  303. // for the hosted swf, which should be relative to the page (not video.js)
  304. // Otherwise this adds a CDN url.
  305. // The CDN also auto-adds a swf URL for that specific version.
  306. if (!options.swf) {
  307. options.swf = 'https://vjs.zencdn.net/swf/' + version + '/video-js.swf';
  308. }
  309. // Generate ID for swf object
  310. var objId = options.techId;
  311. // Merge default flashvars with ones passed in to init
  312. var flashVars = mergeOptions({
  313. // SWF Callback Functions
  314. readyFunction: 'videojs.Flash.onReady',
  315. eventProxyFunction: 'videojs.Flash.onEvent',
  316. errorEventProxyFunction: 'videojs.Flash.onError',
  317. // Player Settings
  318. autoplay: options.autoplay,
  319. preload: options.preload,
  320. loop: options.loop,
  321. muted: options.muted
  322. }, options.flashVars);
  323. // Merge default parames with ones passed in
  324. var params = mergeOptions({
  325. // Opaque is needed to overlay controls, but can affect playback performance
  326. wmode: 'opaque',
  327. // Using bgcolor prevents a white flash when the object is loading
  328. bgcolor: '#000000'
  329. }, options.params);
  330. // Merge default attributes with ones passed in
  331. var attributes = mergeOptions({
  332. // Both ID and Name needed or swf to identify itself
  333. id: objId,
  334. name: objId,
  335. 'class': 'vjs-tech'
  336. }, options.attributes);
  337. this.el_ = Flash.embed(options.swf, flashVars, params, attributes);
  338. this.el_.tech = this;
  339. return this.el_;
  340. };
  341. /**
  342. * Called by {@link Player#play} to play using the `Flash` `Tech`.
  343. */
  344. Flash.prototype.play = function play() {
  345. if (this.ended()) {
  346. this.setCurrentTime(0);
  347. }
  348. this.el_.vjs_play();
  349. };
  350. /**
  351. * Called by {@link Player#pause} to pause using the `Flash` `Tech`.
  352. */
  353. Flash.prototype.pause = function pause() {
  354. this.el_.vjs_pause();
  355. };
  356. /**
  357. * A getter/setter for the `Flash` Tech's source object.
  358. * > Note: Please use {@link Flash#setSource}
  359. *
  360. * @param {Tech~SourceObject} [src]
  361. * The source object you want to set on the `Flash` techs.
  362. *
  363. * @return {Tech~SourceObject|undefined}
  364. * - The current source object when a source is not passed in.
  365. * - undefined when setting
  366. *
  367. * @deprecated Since version 5.
  368. */
  369. Flash.prototype.src = function src(_src) {
  370. if (_src === undefined) {
  371. return this.currentSrc();
  372. }
  373. // Setting src through `src` not `setSrc` will be deprecated
  374. return this.setSrc(_src);
  375. };
  376. /**
  377. * A getter/setter for the `Flash` Tech's source object.
  378. *
  379. * @param {Tech~SourceObject} [src]
  380. * The source object you want to set on the `Flash` techs.
  381. */
  382. Flash.prototype.setSrc = function setSrc(src) {
  383. var _this2 = this;
  384. // Make sure source URL is absolute.
  385. src = Url.getAbsoluteURL(src);
  386. this.el_.vjs_src(src);
  387. // Currently the SWF doesn't autoplay if you load a source later.
  388. // e.g. Load player w/ no source, wait 2s, set src.
  389. if (this.autoplay()) {
  390. this.setTimeout(function () {
  391. return _this2.play();
  392. }, 0);
  393. }
  394. };
  395. /**
  396. * Indicates whether the media is currently seeking to a new position or not.
  397. *
  398. * @return {boolean}
  399. * - True if seeking to a new position
  400. * - False otherwise
  401. */
  402. Flash.prototype.seeking = function seeking() {
  403. return this.lastSeekTarget_ !== undefined;
  404. };
  405. /**
  406. * Returns the current time in seconds that the media is at in playback.
  407. *
  408. * @param {number} time
  409. * Current playtime of the media in seconds.
  410. */
  411. Flash.prototype.setCurrentTime = function setCurrentTime(time) {
  412. var seekable = this.seekable();
  413. if (seekable.length) {
  414. // clamp to the current seekable range
  415. time = time > seekable.start(0) ? time : seekable.start(0);
  416. time = time < seekable.end(seekable.length - 1) ? time : seekable.end(seekable.length - 1);
  417. this.lastSeekTarget_ = time;
  418. this.trigger('seeking');
  419. this.el_.vjs_setProperty('currentTime', time);
  420. _Tech.prototype.setCurrentTime.call(this);
  421. }
  422. };
  423. /**
  424. * Get the current playback time in seconds
  425. *
  426. * @return {number}
  427. * The current time of playback in seconds.
  428. */
  429. Flash.prototype.currentTime = function currentTime() {
  430. // when seeking make the reported time keep up with the requested time
  431. // by reading the time we're seeking to
  432. if (this.seeking()) {
  433. return this.lastSeekTarget_ || 0;
  434. }
  435. return this.el_.vjs_getProperty('currentTime');
  436. };
  437. /**
  438. * Get the current source
  439. *
  440. * @method currentSrc
  441. * @return {Tech~SourceObject}
  442. * The current source
  443. */
  444. Flash.prototype.currentSrc = function currentSrc() {
  445. if (this.currentSource_) {
  446. return this.currentSource_.src;
  447. }
  448. return this.el_.vjs_getProperty('currentSrc');
  449. };
  450. /**
  451. * Get the total duration of the current media.
  452. *
  453. * @return {number}
  454. 8 The total duration of the current media.
  455. */
  456. Flash.prototype.duration = function duration() {
  457. if (this.readyState() === 0) {
  458. return NaN;
  459. }
  460. var duration = this.el_.vjs_getProperty('duration');
  461. return duration >= 0 ? duration : Infinity;
  462. };
  463. /**
  464. * Load media into Tech.
  465. */
  466. Flash.prototype.load = function load() {
  467. this.el_.vjs_load();
  468. };
  469. /**
  470. * Get the poster image that was set on the tech.
  471. */
  472. Flash.prototype.poster = function poster() {
  473. this.el_.vjs_getProperty('poster');
  474. };
  475. /**
  476. * Poster images are not handled by the Flash tech so make this is a no-op.
  477. */
  478. Flash.prototype.setPoster = function setPoster() {};
  479. /**
  480. * Determine the time ranges that can be seeked to in the media.
  481. *
  482. * @return {TimeRange}
  483. * Returns the time ranges that can be seeked to.
  484. */
  485. Flash.prototype.seekable = function seekable() {
  486. var duration = this.duration();
  487. if (duration === 0) {
  488. return createTimeRange();
  489. }
  490. return createTimeRange(0, duration);
  491. };
  492. /**
  493. * Get and create a `TimeRange` object for buffering.
  494. *
  495. * @return {TimeRange}
  496. * The time range object that was created.
  497. */
  498. Flash.prototype.buffered = function buffered() {
  499. var ranges = this.el_.vjs_getProperty('buffered');
  500. if (ranges.length === 0) {
  501. return createTimeRange();
  502. }
  503. return createTimeRange(ranges[0][0], ranges[0][1]);
  504. };
  505. /**
  506. * Get fullscreen support -
  507. *
  508. * Flash does not allow fullscreen through javascript
  509. * so this always returns false.
  510. *
  511. * @return {boolean}
  512. * The Flash tech does not support fullscreen, so it will always return false.
  513. */
  514. Flash.prototype.supportsFullScreen = function supportsFullScreen() {
  515. // Flash does not allow fullscreen through javascript
  516. return false;
  517. };
  518. /**
  519. * Flash does not allow fullscreen through javascript
  520. * so this always returns false.
  521. *
  522. * @return {boolean}
  523. * The Flash tech does not support fullscreen, so it will always return false.
  524. */
  525. Flash.prototype.enterFullScreen = function enterFullScreen() {
  526. return false;
  527. };
  528. /**
  529. * Gets available media playback quality metrics as specified by the W3C's Media
  530. * Playback Quality API.
  531. *
  532. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  533. *
  534. * @return {Object}
  535. * An object with supported media playback quality metrics
  536. */
  537. Flash.prototype.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  538. var videoPlaybackQuality = this.el_.vjs_getProperty('getVideoPlaybackQuality');
  539. if (window_1.performance && typeof window_1.performance.now === 'function') {
  540. videoPlaybackQuality.creationTime = window_1.performance.now();
  541. } else if (window_1.performance && window_1.performance.timing && typeof window_1.performance.timing.navigationStart === 'number') {
  542. videoPlaybackQuality.creationTime = window_1.Date.now() - window_1.performance.timing.navigationStart;
  543. }
  544. return videoPlaybackQuality;
  545. };
  546. return Flash;
  547. }(Tech);
  548. // Create setters and getters for attributes
  549. var _readWrite = ['rtmpConnection', 'rtmpStream', 'preload', 'defaultPlaybackRate', 'playbackRate', 'autoplay', 'loop', 'controls', 'volume', 'muted', 'defaultMuted'];
  550. var _readOnly = ['networkState', 'readyState', 'initialTime', 'startOffsetTime', 'paused', 'ended', 'videoWidth', 'videoHeight'];
  551. var _api = Flash.prototype;
  552. /**
  553. * Create setters for the swf on the element
  554. *
  555. * @param {string} attr
  556. * The name of the parameter
  557. *
  558. * @private
  559. */
  560. function _createSetter(attr) {
  561. var attrUpper = attr.charAt(0).toUpperCase() + attr.slice(1);
  562. _api['set' + attrUpper] = function (val) {
  563. return this.el_.vjs_setProperty(attr, val);
  564. };
  565. }
  566. /**
  567. * Create getters for the swf on the element
  568. *
  569. * @param {string} attr
  570. * The name of the parameter
  571. *
  572. * @private
  573. */
  574. function _createGetter(attr) {
  575. _api[attr] = function () {
  576. return this.el_.vjs_getProperty(attr);
  577. };
  578. }
  579. // Create getter and setters for all read/write attributes
  580. for (var i = 0; i < _readWrite.length; i++) {
  581. _createGetter(_readWrite[i]);
  582. _createSetter(_readWrite[i]);
  583. }
  584. // Create getters for read-only attributes
  585. for (var _i = 0; _i < _readOnly.length; _i++) {
  586. _createGetter(_readOnly[_i]);
  587. }
  588. /** ------------------------------ Getters ------------------------------ **/
  589. /**
  590. * Get the value of `rtmpConnection` from the swf.
  591. *
  592. * @method Flash#rtmpConnection
  593. * @return {string}
  594. * The current value of `rtmpConnection` on the swf.
  595. */
  596. /**
  597. * Get the value of `rtmpStream` from the swf.
  598. *
  599. * @method Flash#rtmpStream
  600. * @return {string}
  601. * The current value of `rtmpStream` on the swf.
  602. */
  603. /**
  604. * Get the value of `preload` from the swf. `preload` indicates
  605. * what should download before the media is interacted with. It can have the following
  606. * values:
  607. * - none: nothing should be downloaded
  608. * - metadata: poster and the first few frames of the media may be downloaded to get
  609. * media dimensions and other metadata
  610. * - auto: allow the media and metadata for the media to be downloaded before
  611. * interaction
  612. *
  613. * @method Flash#preload
  614. * @return {string}
  615. * The value of `preload` from the swf. Will be 'none', 'metadata',
  616. * or 'auto'.
  617. */
  618. /**
  619. * Get the value of `defaultPlaybackRate` from the swf.
  620. *
  621. * @method Flash#defaultPlaybackRate
  622. * @return {number}
  623. * The current value of `defaultPlaybackRate` on the swf.
  624. */
  625. /**
  626. * Get the value of `playbackRate` from the swf. `playbackRate` indicates
  627. * the rate at which the media is currently playing back. Examples:
  628. * - if playbackRate is set to 2, media will play twice as fast.
  629. * - if playbackRate is set to 0.5, media will play half as fast.
  630. *
  631. * @method Flash#playbackRate
  632. * @return {number}
  633. * The value of `playbackRate` from the swf. A number indicating
  634. * the current playback speed of the media, where 1 is normal speed.
  635. */
  636. /**
  637. * Get the value of `autoplay` from the swf. `autoplay` indicates
  638. * that the media should start to play as soon as the page is ready.
  639. *
  640. * @method Flash#autoplay
  641. * @return {boolean}
  642. * - The value of `autoplay` from the swf.
  643. * - True indicates that the media ashould start as soon as the page loads.
  644. * - False indicates that the media should not start as soon as the page loads.
  645. */
  646. /**
  647. * Get the value of `loop` from the swf. `loop` indicates
  648. * that the media should return to the start of the media and continue playing once
  649. * it reaches the end.
  650. *
  651. * @method Flash#loop
  652. * @return {boolean}
  653. * - The value of `loop` from the swf.
  654. * - True indicates that playback should seek back to start once
  655. * the end of a media is reached.
  656. * - False indicates that playback should not loop back to the start when the
  657. * end of the media is reached.
  658. */
  659. /**
  660. * Get the value of `mediaGroup` from the swf.
  661. *
  662. * @method Flash#mediaGroup
  663. * @return {string}
  664. * The current value of `mediaGroup` on the swf.
  665. */
  666. /**
  667. * Get the value of `controller` from the swf.
  668. *
  669. * @method Flash#controller
  670. * @return {string}
  671. * The current value of `controller` on the swf.
  672. */
  673. /**
  674. * Get the value of `controls` from the swf. `controls` indicates
  675. * whether the native flash controls should be shown or hidden.
  676. *
  677. * @method Flash#controls
  678. * @return {boolean}
  679. * - The value of `controls` from the swf.
  680. * - True indicates that native controls should be showing.
  681. * - False indicates that native controls should be hidden.
  682. */
  683. /**
  684. * Get the value of the `volume` from the swf. `volume` indicates the current
  685. * audio level as a percentage in decimal form. This means that 1 is 100%, 0.5 is 50%, and
  686. * so on.
  687. *
  688. * @method Flash#volume
  689. * @return {number}
  690. * The volume percent as a decimal. Value will be between 0-1.
  691. */
  692. /**
  693. * Get the value of the `muted` from the swf. `muted` indicates the current
  694. * audio level should be silent.
  695. *
  696. * @method Flash#muted
  697. * @return {boolean}
  698. * - True if the audio should be set to silent
  699. * - False otherwise
  700. */
  701. /**
  702. * Get the value of `defaultMuted` from the swf. `defaultMuted` indicates
  703. * whether the media should start muted or not. Only changes the default state of the
  704. * media. `muted` and `defaultMuted` can have different values. `muted` indicates the
  705. * current state.
  706. *
  707. * @method Flash#defaultMuted
  708. * @return {boolean}
  709. * - The value of `defaultMuted` from the swf.
  710. * - True indicates that the media should start muted.
  711. * - False indicates that the media should not start muted.
  712. */
  713. /**
  714. * Get the value of `networkState` from the swf. `networkState` indicates
  715. * the current network state. It returns an enumeration from the following list:
  716. * - 0: NETWORK_EMPTY
  717. * - 1: NEWORK_IDLE
  718. * - 2: NETWORK_LOADING
  719. * - 3: NETWORK_NO_SOURCE
  720. *
  721. * @method Flash#networkState
  722. * @return {number}
  723. * The value of `networkState` from the swf. This will be a number
  724. * from the list in the description.
  725. */
  726. /**
  727. * Get the value of `readyState` from the swf. `readyState` indicates
  728. * the current state of the media element. It returns an enumeration from the
  729. * following list:
  730. * - 0: HAVE_NOTHING
  731. * - 1: HAVE_METADATA
  732. * - 2: HAVE_CURRENT_DATA
  733. * - 3: HAVE_FUTURE_DATA
  734. * - 4: HAVE_ENOUGH_DATA
  735. *
  736. * @method Flash#readyState
  737. * @return {number}
  738. * The value of `readyState` from the swf. This will be a number
  739. * from the list in the description.
  740. */
  741. /**
  742. * Get the value of `readyState` from the swf. `readyState` indicates
  743. * the current state of the media element. It returns an enumeration from the
  744. * following list:
  745. * - 0: HAVE_NOTHING
  746. * - 1: HAVE_METADATA
  747. * - 2: HAVE_CURRENT_DATA
  748. * - 3: HAVE_FUTURE_DATA
  749. * - 4: HAVE_ENOUGH_DATA
  750. *
  751. * @method Flash#readyState
  752. * @return {number}
  753. * The value of `readyState` from the swf. This will be a number
  754. * from the list in the description.
  755. */
  756. /**
  757. * Get the value of `initialTime` from the swf.
  758. *
  759. * @method Flash#initialTime
  760. * @return {number}
  761. * The `initialTime` proprety on the swf.
  762. */
  763. /**
  764. * Get the value of `startOffsetTime` from the swf.
  765. *
  766. * @method Flash#startOffsetTime
  767. * @return {number}
  768. * The `startOffsetTime` proprety on the swf.
  769. */
  770. /**
  771. * Get the value of `paused` from the swf. `paused` indicates whether the swf
  772. * is current paused or not.
  773. *
  774. * @method Flash#paused
  775. * @return {boolean}
  776. * The value of `paused` from the swf.
  777. */
  778. /**
  779. * Get the value of `ended` from the swf. `ended` indicates whether
  780. * the media has reached the end or not.
  781. *
  782. * @method Flash#ended
  783. * @return {boolean}
  784. * - True indicates that the media has ended.
  785. * - False indicates that the media has not ended.
  786. *
  787. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-ended}
  788. */
  789. /**
  790. * Get the value of `videoWidth` from the swf. `videoWidth` indicates
  791. * the current width of the media in css pixels.
  792. *
  793. * @method Flash#videoWidth
  794. * @return {number}
  795. * The value of `videoWidth` from the swf. This will be a number
  796. * in css pixels.
  797. */
  798. /**
  799. * Get the value of `videoHeight` from the swf. `videoHeigth` indicates
  800. * the current height of the media in css pixels.
  801. *
  802. * @method Flassh.prototype.videoHeight
  803. * @return {number}
  804. * The value of `videoHeight` from the swf. This will be a number
  805. * in css pixels.
  806. */
  807. /** ------------------------------ Setters ------------------------------ **/
  808. /**
  809. * Set the value of `rtmpConnection` on the swf.
  810. *
  811. * @method Flash#setRtmpConnection
  812. * @param {string} rtmpConnection
  813. * New value to set the `rtmpConnection` property to.
  814. */
  815. /**
  816. * Set the value of `rtmpStream` on the swf.
  817. *
  818. * @method Flash#setRtmpStream
  819. * @param {string} rtmpStream
  820. * New value to set the `rtmpStream` property to.
  821. */
  822. /**
  823. * Set the value of `preload` on the swf. `preload` indicates
  824. * what should download before the media is interacted with. It can have the following
  825. * values:
  826. * - none: nothing should be downloaded
  827. * - metadata: poster and the first few frames of the media may be downloaded to get
  828. * media dimensions and other metadata
  829. * - auto: allow the media and metadata for the media to be downloaded before
  830. * interaction
  831. *
  832. * @method Flash#setPreload
  833. * @param {string} preload
  834. * The value of `preload` to set on the swf. Should be 'none', 'metadata',
  835. * or 'auto'.
  836. */
  837. /**
  838. * Set the value of `defaultPlaybackRate` on the swf.
  839. *
  840. * @method Flash#setDefaultPlaybackRate
  841. * @param {number} defaultPlaybackRate
  842. * New value to set the `defaultPlaybackRate` property to.
  843. */
  844. /**
  845. * Set the value of `playbackRate` on the swf. `playbackRate` indicates
  846. * the rate at which the media is currently playing back. Examples:
  847. * - if playbackRate is set to 2, media will play twice as fast.
  848. * - if playbackRate is set to 0.5, media will play half as fast.
  849. *
  850. * @method Flash#setPlaybackRate
  851. * @param {number} playbackRate
  852. * New value of `playbackRate` on the swf. A number indicating
  853. * the current playback speed of the media, where 1 is normal speed.
  854. */
  855. /**
  856. * Set the value of `autoplay` on the swf. `autoplay` indicates
  857. * that the media should start to play as soon as the page is ready.
  858. *
  859. * @method Flash#setAutoplay
  860. * @param {boolean} autoplay
  861. * - The value of `autoplay` from the swf.
  862. * - True indicates that the media ashould start as soon as the page loads.
  863. * - False indicates that the media should not start as soon as the page loads.
  864. */
  865. /**
  866. * Set the value of `loop` on the swf. `loop` indicates
  867. * that the media should return to the start of the media and continue playing once
  868. * it reaches the end.
  869. *
  870. * @method Flash#setLoop
  871. * @param {boolean} loop
  872. * - True indicates that playback should seek back to start once
  873. * the end of a media is reached.
  874. * - False indicates that playback should not loop back to the start when the
  875. * end of the media is reached.
  876. */
  877. /**
  878. * Set the value of `mediaGroup` on the swf.
  879. *
  880. * @method Flash#setMediaGroup
  881. * @param {string} mediaGroup
  882. * New value of `mediaGroup` to set on the swf.
  883. */
  884. /**
  885. * Set the value of `controller` on the swf.
  886. *
  887. * @method Flash#setController
  888. * @param {string} controller
  889. * New value the current value of `controller` on the swf.
  890. */
  891. /**
  892. * Get the value of `controls` from the swf. `controls` indicates
  893. * whether the native flash controls should be shown or hidden.
  894. *
  895. * @method Flash#controls
  896. * @return {boolean}
  897. * - The value of `controls` from the swf.
  898. * - True indicates that native controls should be showing.
  899. * - False indicates that native controls should be hidden.
  900. */
  901. /**
  902. * Set the value of the `volume` on the swf. `volume` indicates the current
  903. * audio level as a percentage in decimal form. This means that 1 is 100%, 0.5 is 50%, and
  904. * so on.
  905. *
  906. * @method Flash#setVolume
  907. * @param {number} percentAsDecimal
  908. * The volume percent as a decimal. Value will be between 0-1.
  909. */
  910. /**
  911. * Set the value of the `muted` on the swf. `muted` indicates that the current
  912. * audio level should be silent.
  913. *
  914. * @method Flash#setMuted
  915. * @param {boolean} muted
  916. * - True if the audio should be set to silent
  917. * - False otherwise
  918. */
  919. /**
  920. * Set the value of `defaultMuted` on the swf. `defaultMuted` indicates
  921. * whether the media should start muted or not. Only changes the default state of the
  922. * media. `muted` and `defaultMuted` can have different values. `muted` indicates the
  923. * current state.
  924. *
  925. * @method Flash#setDefaultMuted
  926. * @param {boolean} defaultMuted
  927. * - True indicates that the media should start muted.
  928. * - False indicates that the media should not start muted.
  929. */
  930. /* Flash Support Testing -------------------------------------------------------- */
  931. /**
  932. * Check if the Flash tech is currently supported.
  933. *
  934. * @return {boolean}
  935. * - True for Chrome and Safari Desktop and Microsoft Edge and if flash tech is supported
  936. * - False otherwise
  937. */
  938. Flash.isSupported = function () {
  939. // for Chrome Desktop and Safari Desktop
  940. if (videojs.browser.IS_CHROME && (!videojs.browser.IS_ANDROID || !videojs.browser.IS_IOS) || videojs.browser.IS_SAFARI && !videojs.browser.IS_IOS || videojs.browser.IS_EDGE) {
  941. return true;
  942. }
  943. // for other browsers
  944. return Flash.version()[0] >= 10;
  945. };
  946. // Add Source Handler pattern functions to this tech
  947. Tech.withSourceHandlers(Flash);
  948. /*
  949. * Native source handler for flash, simply passes the source to the swf element.
  950. *
  951. * @property {Tech~SourceObject} source
  952. * The source object
  953. *
  954. * @property {Flash} tech
  955. * The instance of the Flash tech
  956. */
  957. Flash.nativeSourceHandler = {};
  958. /**
  959. * Check if the Flash can play the given mime type.
  960. *
  961. * @param {string} type
  962. * The mimetype to check
  963. *
  964. * @return {string}
  965. * 'maybe', or '' (empty string)
  966. */
  967. Flash.nativeSourceHandler.canPlayType = function (type) {
  968. if (type in Flash.formats) {
  969. return 'maybe';
  970. }
  971. return '';
  972. };
  973. /**
  974. * Check if the media element can handle a source natively.
  975. *
  976. * @param {Tech~SourceObject} source
  977. * The source object
  978. *
  979. * @param {Object} [options]
  980. * Options to be passed to the tech.
  981. *
  982. * @return {string}
  983. * 'maybe', or '' (empty string).
  984. */
  985. Flash.nativeSourceHandler.canHandleSource = function (source, options) {
  986. var type = void 0;
  987. /**
  988. * Guess the mime type of a file if it does not have one
  989. *
  990. * @param {Tech~SourceObject} src
  991. * The source object to guess the mime type for
  992. *
  993. * @return {string}
  994. * The mime type that was guessed
  995. */
  996. function guessMimeType(src) {
  997. var ext = Url.getFileExtension(src);
  998. if (ext) {
  999. return 'video/' + ext;
  1000. }
  1001. return '';
  1002. }
  1003. if (!source.type) {
  1004. type = guessMimeType(source.src);
  1005. } else {
  1006. // Strip code information from the type because we don't get that specific
  1007. type = source.type.replace(/;.*/, '').toLowerCase();
  1008. }
  1009. return Flash.nativeSourceHandler.canPlayType(type);
  1010. };
  1011. /**
  1012. * Pass the source to the swf.
  1013. *
  1014. * @param {Tech~SourceObject} source
  1015. * The source object
  1016. *
  1017. * @param {Flash} tech
  1018. * The instance of the Flash tech
  1019. *
  1020. * @param {Object} [options]
  1021. * The options to pass to the source
  1022. */
  1023. Flash.nativeSourceHandler.handleSource = function (source, tech, options) {
  1024. tech.setSrc(source.src);
  1025. };
  1026. /**
  1027. * noop for native source handler dispose, as cleanup will happen automatically.
  1028. */
  1029. Flash.nativeSourceHandler.dispose = function () {};
  1030. // Register the native source handler
  1031. Flash.registerSourceHandler(Flash.nativeSourceHandler);
  1032. /**
  1033. * Flash supported mime types.
  1034. *
  1035. * @constant {Object}
  1036. */
  1037. Flash.formats = {
  1038. 'video/flv': 'FLV',
  1039. 'video/x-flv': 'FLV',
  1040. 'video/mp4': 'MP4',
  1041. 'video/m4v': 'MP4'
  1042. };
  1043. /**
  1044. * Called when the the swf is "ready", and makes sure that the swf is really
  1045. * ready using {@link Flash#checkReady}
  1046. *
  1047. * @param {Object} currSwf
  1048. * The current swf object
  1049. */
  1050. Flash.onReady = function (currSwf) {
  1051. var el = Dom.$('#' + currSwf);
  1052. var tech = el && el.tech;
  1053. // if there is no el then the tech has been disposed
  1054. // and the tech element was removed from the player div
  1055. if (tech && tech.el()) {
  1056. // check that the flash object is really ready
  1057. Flash.checkReady(tech);
  1058. }
  1059. };
  1060. /**
  1061. * The SWF isn't always ready when it says it is. Sometimes the API functions still
  1062. * need to be added to the object. If it's not ready, we set a timeout to check again
  1063. * shortly.
  1064. *
  1065. * @param {Flash} tech
  1066. * The instance of the flash tech to check.
  1067. */
  1068. Flash.checkReady = function (tech) {
  1069. // stop worrying if the tech has been disposed
  1070. if (!tech.el()) {
  1071. return;
  1072. }
  1073. // check if API property exists
  1074. if (tech.el().vjs_getProperty) {
  1075. // tell tech it's ready
  1076. tech.triggerReady();
  1077. } else {
  1078. // wait longer
  1079. this.setTimeout(function () {
  1080. Flash.checkReady(tech);
  1081. }, 50);
  1082. }
  1083. };
  1084. /**
  1085. * Trigger events from the swf on the Flash Tech.
  1086. *
  1087. * @param {number} swfID
  1088. * The id of the swf that had the event
  1089. *
  1090. * @param {string} eventName
  1091. * The name of the event to trigger
  1092. */
  1093. Flash.onEvent = function (swfID, eventName) {
  1094. var tech = Dom.$('#' + swfID).tech;
  1095. var args = Array.prototype.slice.call(arguments, 2);
  1096. // dispatch Flash events asynchronously for two reasons:
  1097. // - Flash swallows any exceptions generated by javascript it
  1098. // invokes
  1099. // - Flash is suspended until the javascript returns which may cause
  1100. // playback performance issues
  1101. tech.setTimeout(function () {
  1102. tech.trigger(eventName, args);
  1103. }, 1);
  1104. };
  1105. /**
  1106. * Log errors from the swf on the Flash tech.
  1107. *
  1108. * @param {number} swfID
  1109. * The id of the swf that had an error.
  1110. *
  1111. * @param {string} err
  1112. * The error to set on the Flash Tech.
  1113. *
  1114. * @return {MediaError|undefined}
  1115. * - Returns a MediaError when err is 'srcnotfound'
  1116. * - Returns undefined otherwise.
  1117. */
  1118. Flash.onError = function (swfID, err) {
  1119. var tech = Dom.$('#' + swfID).tech;
  1120. // trigger MEDIA_ERR_SRC_NOT_SUPPORTED
  1121. if (err === 'srcnotfound') {
  1122. return tech.error(4);
  1123. }
  1124. // trigger a custom error
  1125. if (typeof err === 'string') {
  1126. tech.error('FLASH: ' + err);
  1127. } else {
  1128. err.origin = 'flash';
  1129. tech.error(err);
  1130. }
  1131. };
  1132. /**
  1133. * Get the current version of Flash that is in use on the page.
  1134. *
  1135. * @return {Array}
  1136. * an array of versions that are available.
  1137. */
  1138. Flash.version = function () {
  1139. var version$$1 = '0,0,0';
  1140. // IE
  1141. try {
  1142. version$$1 = new window_1.ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
  1143. // other browsers
  1144. } catch (e) {
  1145. try {
  1146. if (navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
  1147. version$$1 = (navigator.plugins['Shockwave Flash 2.0'] || navigator.plugins['Shockwave Flash']).description.replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
  1148. }
  1149. } catch (err) {
  1150. // satisfy linter
  1151. }
  1152. }
  1153. return version$$1.split(',');
  1154. };
  1155. /**
  1156. * Only use for non-iframe embeds.
  1157. *
  1158. * @param {Object} swf
  1159. * The videojs-swf object.
  1160. *
  1161. * @param {Object} flashVars
  1162. * Names and values to use as flash option variables.
  1163. *
  1164. * @param {Object} params
  1165. * Style parameters to set on the object.
  1166. *
  1167. * @param {Object} attributes
  1168. * Attributes to set on the element.
  1169. *
  1170. * @return {Element}
  1171. * The embeded Flash DOM element.
  1172. */
  1173. Flash.embed = function (swf, flashVars, params, attributes) {
  1174. var code = Flash.getEmbedCode(swf, flashVars, params, attributes);
  1175. // Get element by embedding code and retrieving created element
  1176. var obj = Dom.createEl('div', { innerHTML: code }).childNodes[0];
  1177. return obj;
  1178. };
  1179. /**
  1180. * Only use for non-iframe embeds.
  1181. *
  1182. * @param {Object} swf
  1183. * The videojs-swf object.
  1184. *
  1185. * @param {Object} flashVars
  1186. * Names and values to use as flash option variables.
  1187. *
  1188. * @param {Object} params
  1189. * Style parameters to set on the object.
  1190. *
  1191. * @param {Object} attributes
  1192. * Attributes to set on the element.
  1193. *
  1194. * @return {Element}
  1195. * The embeded Flash DOM element.
  1196. */
  1197. Flash.getEmbedCode = function (swf, flashVars, params, attributes) {
  1198. var objTag = '<object type="application/x-shockwave-flash" ';
  1199. var flashVarsString = '';
  1200. var paramsString = '';
  1201. var attrsString = '';
  1202. // Convert flash vars to string
  1203. if (flashVars) {
  1204. Object.getOwnPropertyNames(flashVars).forEach(function (key) {
  1205. flashVarsString += key + '=' + flashVars[key] + '&amp;';
  1206. });
  1207. }
  1208. // Add swf, flashVars, and other default params
  1209. params = mergeOptions({
  1210. movie: swf,
  1211. flashvars: flashVarsString,
  1212. // Required to talk to swf
  1213. allowScriptAccess: 'always',
  1214. // All should be default, but having security issues.
  1215. allowNetworking: 'all'
  1216. }, params);
  1217. // Create param tags string
  1218. Object.getOwnPropertyNames(params).forEach(function (key) {
  1219. paramsString += '<param name="' + key + '" value="' + params[key] + '" />';
  1220. });
  1221. attributes = mergeOptions({
  1222. // Add swf to attributes (need both for IE and Others to work)
  1223. data: swf,
  1224. // Default to 100% width/height
  1225. width: '100%',
  1226. height: '100%'
  1227. }, attributes);
  1228. // Create Attributes string
  1229. Object.getOwnPropertyNames(attributes).forEach(function (key) {
  1230. attrsString += key + '="' + attributes[key] + '" ';
  1231. });
  1232. return '' + objTag + attrsString + '>' + paramsString + '</object>';
  1233. };
  1234. // Run Flash through the RTMP decorator
  1235. FlashRtmpDecorator(Flash);
  1236. if (Tech.getTech('Flash')) {
  1237. videojs.log.warn('Not using videojs-flash as it appears to already be registered');
  1238. videojs.log.warn('videojs-flash should only be used with video.js@6 and above');
  1239. } else {
  1240. videojs.registerTech('Flash', Flash);
  1241. }
  1242. Flash.VERSION = version$1;
  1243. return Flash;
  1244. })));