flash.js 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _tech = require('./tech');
  4. var _tech2 = _interopRequireDefault(_tech);
  5. var _dom = require('../utils/dom.js');
  6. var Dom = _interopRequireWildcard(_dom);
  7. var _url = require('../utils/url.js');
  8. var Url = _interopRequireWildcard(_url);
  9. var _timeRanges = require('../utils/time-ranges.js');
  10. var _flashRtmp = require('./flash-rtmp');
  11. var _flashRtmp2 = _interopRequireDefault(_flashRtmp);
  12. var _component = require('../component');
  13. var _component2 = _interopRequireDefault(_component);
  14. var _window = require('global/window');
  15. var _window2 = _interopRequireDefault(_window);
  16. var _obj = require('../utils/obj');
  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; } }
  18. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  19. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20. 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; }
  21. 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; } /**
  22. * @file flash.js
  23. * VideoJS-SWF - Custom Flash Player with HTML5-ish API
  24. * https://github.com/zencoder/video-js-swf
  25. * Not using setupTriggers. Using global onEvent func to distribute events
  26. */
  27. var navigator = _window2['default'].navigator;
  28. /**
  29. * Flash Media Controller - Wrapper for Flash Media API
  30. *
  31. * @mixes FlashRtmpDecorator
  32. * @mixes Tech~SouceHandlerAdditions
  33. * @extends Tech
  34. */
  35. var Flash = function (_Tech) {
  36. _inherits(Flash, _Tech);
  37. /**
  38. * Create an instance of this Tech.
  39. *
  40. * @param {Object} [options]
  41. * The key/value store of player options.
  42. *
  43. * @param {Component~ReadyCallback} ready
  44. * Callback function to call when the `Flash` Tech is ready.
  45. */
  46. function Flash(options, ready) {
  47. _classCallCheck(this, Flash);
  48. // Set the source when ready
  49. var _this = _possibleConstructorReturn(this, _Tech.call(this, options, ready));
  50. if (options.source) {
  51. _this.ready(function () {
  52. this.setSource(options.source);
  53. }, true);
  54. }
  55. // Having issues with Flash reloading on certain page actions (hide/resize/fullscreen) in certain browsers
  56. // This allows resetting the playhead when we catch the reload
  57. if (options.startTime) {
  58. _this.ready(function () {
  59. this.load();
  60. this.play();
  61. this.currentTime(options.startTime);
  62. }, true);
  63. }
  64. // Add global window functions that the swf expects
  65. // A 4.x workflow we weren't able to solve for in 5.0
  66. // because of the need to hard code these functions
  67. // into the swf for security reasons
  68. _window2['default'].videojs = _window2['default'].videojs || {};
  69. _window2['default'].videojs.Flash = _window2['default'].videojs.Flash || {};
  70. _window2['default'].videojs.Flash.onReady = Flash.onReady;
  71. _window2['default'].videojs.Flash.onEvent = Flash.onEvent;
  72. _window2['default'].videojs.Flash.onError = Flash.onError;
  73. _this.on('seeked', function () {
  74. this.lastSeekTarget_ = undefined;
  75. });
  76. return _this;
  77. }
  78. /**
  79. * Create the `Flash` Tech's DOM element.
  80. *
  81. * @return {Element}
  82. * The element that gets created.
  83. */
  84. Flash.prototype.createEl = function createEl() {
  85. var options = this.options_;
  86. // If video.js is hosted locally you should also set the location
  87. // for the hosted swf, which should be relative to the page (not video.js)
  88. // Otherwise this adds a CDN url.
  89. // The CDN also auto-adds a swf URL for that specific version.
  90. if (!options.swf) {
  91. var ver = '5.3.0';
  92. options.swf = '//vjs.zencdn.net/swf/' + ver + '/video-js.swf';
  93. }
  94. // Generate ID for swf object
  95. var objId = options.techId;
  96. // Merge default flashvars with ones passed in to init
  97. var flashVars = (0, _obj.assign)({
  98. // SWF Callback Functions
  99. readyFunction: 'videojs.Flash.onReady',
  100. eventProxyFunction: 'videojs.Flash.onEvent',
  101. errorEventProxyFunction: 'videojs.Flash.onError',
  102. // Player Settings
  103. autoplay: options.autoplay,
  104. preload: options.preload,
  105. loop: options.loop,
  106. muted: options.muted
  107. }, options.flashVars);
  108. // Merge default parames with ones passed in
  109. var params = (0, _obj.assign)({
  110. // Opaque is needed to overlay controls, but can affect playback performance
  111. wmode: 'opaque',
  112. // Using bgcolor prevents a white flash when the object is loading
  113. bgcolor: '#000000'
  114. }, options.params);
  115. // Merge default attributes with ones passed in
  116. var attributes = (0, _obj.assign)({
  117. // Both ID and Name needed or swf to identify itself
  118. id: objId,
  119. name: objId,
  120. 'class': 'vjs-tech'
  121. }, options.attributes);
  122. this.el_ = Flash.embed(options.swf, flashVars, params, attributes);
  123. this.el_.tech = this;
  124. return this.el_;
  125. };
  126. /**
  127. * Called by {@link Player#play} to play using the `Flash` `Tech`.
  128. */
  129. Flash.prototype.play = function play() {
  130. if (this.ended()) {
  131. this.setCurrentTime(0);
  132. }
  133. this.el_.vjs_play();
  134. };
  135. /**
  136. * Called by {@link Player#pause} to pause using the `Flash` `Tech`.
  137. */
  138. Flash.prototype.pause = function pause() {
  139. this.el_.vjs_pause();
  140. };
  141. /**
  142. * A getter/setter for the `Flash` Tech's source object.
  143. * > Note: Please use {@link Flash#setSource}
  144. *
  145. * @param {Tech~SourceObject} [src]
  146. * The source object you want to set on the `Flash` techs.
  147. *
  148. * @return {Tech~SourceObject|undefined}
  149. * - The current source object when a source is not passed in.
  150. * - undefined when setting
  151. *
  152. * @deprecated Since version 5.
  153. */
  154. Flash.prototype.src = function src(_src) {
  155. if (_src === undefined) {
  156. return this.currentSrc();
  157. }
  158. // Setting src through `src` not `setSrc` will be deprecated
  159. return this.setSrc(_src);
  160. };
  161. /**
  162. * A getter/setter for the `Flash` Tech's source object.
  163. *
  164. * @param {Tech~SourceObject} [src]
  165. * The source object you want to set on the `Flash` techs.
  166. *
  167. * @return {Tech~SourceObject|undefined}
  168. * - The current source object when a source is not passed in.
  169. * - undefined when setting
  170. */
  171. Flash.prototype.setSrc = function setSrc(src) {
  172. var _this2 = this;
  173. // Make sure source URL is absolute.
  174. src = Url.getAbsoluteURL(src);
  175. this.el_.vjs_src(src);
  176. // Currently the SWF doesn't autoplay if you load a source later.
  177. // e.g. Load player w/ no source, wait 2s, set src.
  178. if (this.autoplay()) {
  179. this.setTimeout(function () {
  180. return _this2.play();
  181. }, 0);
  182. }
  183. };
  184. /**
  185. * Indicates whether the media is currently seeking to a new position or not.
  186. *
  187. * @return {boolean}
  188. * - True if seeking to a new position
  189. * - False otherwise
  190. */
  191. Flash.prototype.seeking = function seeking() {
  192. return this.lastSeekTarget_ !== undefined;
  193. };
  194. /**
  195. * Returns the current time in seconds that the media is at in playback.
  196. *
  197. * @param {number} time
  198. * Current playtime of the media in seconds.
  199. */
  200. Flash.prototype.setCurrentTime = function setCurrentTime(time) {
  201. var seekable = this.seekable();
  202. if (seekable.length) {
  203. // clamp to the current seekable range
  204. time = time > seekable.start(0) ? time : seekable.start(0);
  205. time = time < seekable.end(seekable.length - 1) ? time : seekable.end(seekable.length - 1);
  206. this.lastSeekTarget_ = time;
  207. this.trigger('seeking');
  208. this.el_.vjs_setProperty('currentTime', time);
  209. _Tech.prototype.setCurrentTime.call(this);
  210. }
  211. };
  212. /**
  213. * Get the current playback time in seconds
  214. *
  215. * @return {number}
  216. * The current time of playback in seconds.
  217. */
  218. Flash.prototype.currentTime = function currentTime() {
  219. // when seeking make the reported time keep up with the requested time
  220. // by reading the time we're seeking to
  221. if (this.seeking()) {
  222. return this.lastSeekTarget_ || 0;
  223. }
  224. return this.el_.vjs_getProperty('currentTime');
  225. };
  226. /**
  227. * Get the current source
  228. *
  229. * @method currentSrc
  230. * @return {Tech~SourceObject}
  231. * The current source
  232. */
  233. Flash.prototype.currentSrc = function currentSrc() {
  234. if (this.currentSource_) {
  235. return this.currentSource_.src;
  236. }
  237. return this.el_.vjs_getProperty('currentSrc');
  238. };
  239. /**
  240. * Get the total duration of the current media.
  241. *
  242. * @return {number}
  243. 8 The total duration of the current media.
  244. */
  245. Flash.prototype.duration = function duration() {
  246. if (this.readyState() === 0) {
  247. return NaN;
  248. }
  249. var duration = this.el_.vjs_getProperty('duration');
  250. return duration >= 0 ? duration : Infinity;
  251. };
  252. /**
  253. * Load media into Tech.
  254. */
  255. Flash.prototype.load = function load() {
  256. this.el_.vjs_load();
  257. };
  258. /**
  259. * Get the poster image that was set on the tech.
  260. */
  261. Flash.prototype.poster = function poster() {
  262. this.el_.vjs_getProperty('poster');
  263. };
  264. /**
  265. * Poster images are not handled by the Flash tech so make this is a no-op.
  266. */
  267. Flash.prototype.setPoster = function setPoster() {};
  268. /**
  269. * Determine the time ranges that can be seeked to in the media.
  270. *
  271. * @return {TimeRange}
  272. * Returns the time ranges that can be seeked to.
  273. */
  274. Flash.prototype.seekable = function seekable() {
  275. var duration = this.duration();
  276. if (duration === 0) {
  277. return (0, _timeRanges.createTimeRange)();
  278. }
  279. return (0, _timeRanges.createTimeRange)(0, duration);
  280. };
  281. /**
  282. * Get and create a `TimeRange` object for buffering.
  283. *
  284. * @return {TimeRange}
  285. * The time range object that was created.
  286. */
  287. Flash.prototype.buffered = function buffered() {
  288. var ranges = this.el_.vjs_getProperty('buffered');
  289. if (ranges.length === 0) {
  290. return (0, _timeRanges.createTimeRange)();
  291. }
  292. return (0, _timeRanges.createTimeRange)(ranges[0][0], ranges[0][1]);
  293. };
  294. /**
  295. * Get fullscreen support -
  296. *
  297. * Flash does not allow fullscreen through javascript
  298. * so this always returns false.
  299. *
  300. * @return {boolean}
  301. * The Flash tech does not support fullscreen, so it will always return false.
  302. */
  303. Flash.prototype.supportsFullScreen = function supportsFullScreen() {
  304. // Flash does not allow fullscreen through javascript
  305. return false;
  306. };
  307. /**
  308. * Flash does not allow fullscreen through javascript
  309. * so this always returns false.
  310. *
  311. * @return {boolean}
  312. * The Flash tech does not support fullscreen, so it will always return false.
  313. */
  314. Flash.prototype.enterFullScreen = function enterFullScreen() {
  315. return false;
  316. };
  317. return Flash;
  318. }(_tech2['default']);
  319. // Create setters and getters for attributes
  320. var _api = Flash.prototype;
  321. var _readWrite = 'rtmpConnection,rtmpStream,preload,defaultPlaybackRate,playbackRate,autoplay,loop,mediaGroup,controller,controls,volume,muted,defaultMuted'.split(',');
  322. var _readOnly = 'networkState,readyState,initialTime,startOffsetTime,paused,ended,videoWidth,videoHeight'.split(',');
  323. function _createSetter(attr) {
  324. var attrUpper = attr.charAt(0).toUpperCase() + attr.slice(1);
  325. _api['set' + attrUpper] = function (val) {
  326. return this.el_.vjs_setProperty(attr, val);
  327. };
  328. }
  329. function _createGetter(attr) {
  330. _api[attr] = function () {
  331. return this.el_.vjs_getProperty(attr);
  332. };
  333. }
  334. // Create getter and setters for all read/write attributes
  335. for (var i = 0; i < _readWrite.length; i++) {
  336. _createGetter(_readWrite[i]);
  337. _createSetter(_readWrite[i]);
  338. }
  339. // Create getters for read-only attributes
  340. for (var _i = 0; _i < _readOnly.length; _i++) {
  341. _createGetter(_readOnly[_i]);
  342. }
  343. /** ------------------------------ Getters ------------------------------ **/
  344. /**
  345. * Get the value of `rtmpConnection` from the swf.
  346. *
  347. * @method Flash#rtmpConnection
  348. * @return {string}
  349. * The current value of `rtmpConnection` on the swf.
  350. */
  351. /**
  352. * Get the value of `rtmpStream` from the swf.
  353. *
  354. * @method Flash#rtmpStream
  355. * @return {string}
  356. * The current value of `rtmpStream` on the swf.
  357. */
  358. /**
  359. * Get the value of `preload` from the swf. `preload` indicates
  360. * what should download before the media is interacted with. It can have the following
  361. * values:
  362. * - none: nothing should be downloaded
  363. * - metadata: poster and the first few frames of the media may be downloaded to get
  364. * media dimensions and other metadata
  365. * - auto: allow the media and metadata for the media to be downloaded before
  366. * interaction
  367. *
  368. * @method Flash#preload
  369. * @return {string}
  370. * The value of `preload` from the swf. Will be 'none', 'metadata',
  371. * or 'auto'.
  372. */
  373. /**
  374. * Get the value of `defaultPlaybackRate` from the swf.
  375. *
  376. * @method Flash#defaultPlaybackRate
  377. * @return {number}
  378. * The current value of `defaultPlaybackRate` on the swf.
  379. */
  380. /**
  381. * Get the value of `playbackRate` from the swf. `playbackRate` indicates
  382. * the rate at which the media is currently playing back. Examples:
  383. * - if playbackRate is set to 2, media will play twice as fast.
  384. * - if playbackRate is set to 0.5, media will play half as fast.
  385. *
  386. * @method Flash#playbackRate
  387. * @return {number}
  388. * The value of `playbackRate` from the swf. A number indicating
  389. * the current playback speed of the media, where 1 is normal speed.
  390. */
  391. /**
  392. * Get the value of `autoplay` from the swf. `autoplay` indicates
  393. * that the media should start to play as soon as the page is ready.
  394. *
  395. * @method Flash#autoplay
  396. * @return {boolean}
  397. * - The value of `autoplay` from the swf.
  398. * - True indicates that the media ashould start as soon as the page loads.
  399. * - False indicates that the media should not start as soon as the page loads.
  400. */
  401. /**
  402. * Get the value of `loop` from the swf. `loop` indicates
  403. * that the media should return to the start of the media and continue playing once
  404. * it reaches the end.
  405. *
  406. * @method Flash#loop
  407. * @return {boolean}
  408. * - The value of `loop` from the swf.
  409. * - True indicates that playback should seek back to start once
  410. * the end of a media is reached.
  411. * - False indicates that playback should not loop back to the start when the
  412. * end of the media is reached.
  413. */
  414. /**
  415. * Get the value of `mediaGroup` from the swf.
  416. *
  417. * @method Flash#mediaGroup
  418. * @return {string}
  419. * The current value of `mediaGroup` on the swf.
  420. */
  421. /**
  422. * Get the value of `controller` from the swf.
  423. *
  424. * @method Flash#controller
  425. * @return {string}
  426. * The current value of `controller` on the swf.
  427. */
  428. /**
  429. * Get the value of `controls` from the swf. `controls` indicates
  430. * whether the native flash controls should be shown or hidden.
  431. *
  432. * @method Flash#controls
  433. * @return {boolean}
  434. * - The value of `controls` from the swf.
  435. * - True indicates that native controls should be showing.
  436. * - False indicates that native controls should be hidden.
  437. */
  438. /**
  439. * Get the value of the `volume` from the swf. `volume` indicates the current
  440. * audio level as a percentage in decimal form. This means that 1 is 100%, 0.5 is 50%, and
  441. * so on.
  442. *
  443. * @method Flash#volume
  444. * @return {number}
  445. * The volume percent as a decimal. Value will be between 0-1.
  446. */
  447. /**
  448. * Get the value of the `muted` from the swf. `muted` indicates the current
  449. * audio level should be silent.
  450. *
  451. * @method Flash#muted
  452. * @return {boolean}
  453. * - True if the audio should be set to silent
  454. * - False otherwise
  455. */
  456. /**
  457. * Get the value of `defaultMuted` from the swf. `defaultMuted` indicates
  458. * whether the media should start muted or not. Only changes the default state of the
  459. * media. `muted` and `defaultMuted` can have different values. `muted` indicates the
  460. * current state.
  461. *
  462. * @method Flash#defaultMuted
  463. * @return {boolean}
  464. * - The value of `defaultMuted` from the swf.
  465. * - True indicates that the media should start muted.
  466. * - False indicates that the media should not start muted.
  467. */
  468. /**
  469. * Get the value of `networkState` from the swf. `networkState` indicates
  470. * the current network state. It returns an enumeration from the following list:
  471. * - 0: NETWORK_EMPTY
  472. * - 1: NEWORK_IDLE
  473. * - 2: NETWORK_LOADING
  474. * - 3: NETWORK_NO_SOURCE
  475. *
  476. * @method Flash#networkState
  477. * @return {number}
  478. * The value of `networkState` from the swf. This will be a number
  479. * from the list in the description.
  480. */
  481. /**
  482. * Get the value of `readyState` from the swf. `readyState` indicates
  483. * the current state of the media element. It returns an enumeration from the
  484. * following list:
  485. * - 0: HAVE_NOTHING
  486. * - 1: HAVE_METADATA
  487. * - 2: HAVE_CURRENT_DATA
  488. * - 3: HAVE_FUTURE_DATA
  489. * - 4: HAVE_ENOUGH_DATA
  490. *
  491. * @method Flash#readyState
  492. * @return {number}
  493. * The value of `readyState` from the swf. This will be a number
  494. * from the list in the description.
  495. */
  496. /**
  497. * Get the value of `readyState` from the swf. `readyState` indicates
  498. * the current state of the media element. It returns an enumeration from the
  499. * following list:
  500. * - 0: HAVE_NOTHING
  501. * - 1: HAVE_METADATA
  502. * - 2: HAVE_CURRENT_DATA
  503. * - 3: HAVE_FUTURE_DATA
  504. * - 4: HAVE_ENOUGH_DATA
  505. *
  506. * @method Flash#readyState
  507. * @return {number}
  508. * The value of `readyState` from the swf. This will be a number
  509. * from the list in the description.
  510. */
  511. /**
  512. * Get the value of `initialTime` from the swf.
  513. *
  514. * @method Flash#initialTime
  515. * @return {number}
  516. * The `initialTime` proprety on the swf.
  517. */
  518. /**
  519. * Get the value of `startOffsetTime` from the swf.
  520. *
  521. * @method Flash#startOffsetTime
  522. * @return {number}
  523. * The `startOffsetTime` proprety on the swf.
  524. */
  525. /**
  526. * Get the value of `paused` from the swf. `paused` indicates whether the swf
  527. * is current paused or not.
  528. *
  529. * @method Flash#paused
  530. * @return {boolean}
  531. * The value of `paused` from the swf.
  532. */
  533. /**
  534. * Get the value of `ended` from the swf. `ended` indicates whether
  535. * the media has reached the end or not.
  536. *
  537. * @method Flash#ended
  538. * @return {boolean}
  539. * - True indicates that the media has ended.
  540. * - False indicates that the media has not ended.
  541. *
  542. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-ended}
  543. */
  544. /**
  545. * Get the value of `videoWidth` from the swf. `videoWidth` indicates
  546. * the current width of the media in css pixels.
  547. *
  548. * @method Flash#videoWidth
  549. * @return {number}
  550. * The value of `videoWidth` from the swf. This will be a number
  551. * in css pixels.
  552. */
  553. /**
  554. * Get the value of `videoHeight` from the swf. `videoHeigth` indicates
  555. * the current height of the media in css pixels.
  556. *
  557. * @method Flassh.prototype.videoHeight
  558. * @return {number}
  559. * The value of `videoHeight` from the swf. This will be a number
  560. * in css pixels.
  561. */
  562. /** ------------------------------ Setters ------------------------------ **/
  563. /**
  564. * Set the value of `rtmpConnection` on the swf.
  565. *
  566. * @method Flash#setRtmpConnection
  567. * @param {string} rtmpConnection
  568. * New value to set the `rtmpConnection` property to.
  569. */
  570. /**
  571. * Set the value of `rtmpStream` on the swf.
  572. *
  573. * @method Flash#setRtmpStream
  574. * @param {string} rtmpStream
  575. * New value to set the `rtmpStream` property to.
  576. */
  577. /**
  578. * Set the value of `preload` on the swf. `preload` indicates
  579. * what should download before the media is interacted with. It can have the following
  580. * values:
  581. * - none: nothing should be downloaded
  582. * - metadata: poster and the first few frames of the media may be downloaded to get
  583. * media dimensions and other metadata
  584. * - auto: allow the media and metadata for the media to be downloaded before
  585. * interaction
  586. *
  587. * @method Flash#setPreload
  588. * @param {string} preload
  589. * The value of `preload` to set on the swf. Should be 'none', 'metadata',
  590. * or 'auto'.
  591. */
  592. /**
  593. * Set the value of `defaultPlaybackRate` on the swf.
  594. *
  595. * @method Flash#setDefaultPlaybackRate
  596. * @param {number} defaultPlaybackRate
  597. * New value to set the `defaultPlaybackRate` property to.
  598. */
  599. /**
  600. * Set the value of `playbackRate` on the swf. `playbackRate` indicates
  601. * the rate at which the media is currently playing back. Examples:
  602. * - if playbackRate is set to 2, media will play twice as fast.
  603. * - if playbackRate is set to 0.5, media will play half as fast.
  604. *
  605. * @method Flash#setPlaybackRate
  606. * @param {number} playbackRate
  607. * New value of `playbackRate` on the swf. A number indicating
  608. * the current playback speed of the media, where 1 is normal speed.
  609. */
  610. /**
  611. * Set the value of `autoplay` on the swf. `autoplay` indicates
  612. * that the media should start to play as soon as the page is ready.
  613. *
  614. * @method Flash#setAutoplay
  615. * @param {boolean} autoplay
  616. * - The value of `autoplay` from the swf.
  617. * - True indicates that the media ashould start as soon as the page loads.
  618. * - False indicates that the media should not start as soon as the page loads.
  619. */
  620. /**
  621. * Set the value of `loop` on the swf. `loop` indicates
  622. * that the media should return to the start of the media and continue playing once
  623. * it reaches the end.
  624. *
  625. * @method Flash#setLoop
  626. * @param {boolean} loop
  627. * - True indicates that playback should seek back to start once
  628. * the end of a media is reached.
  629. * - False indicates that playback should not loop back to the start when the
  630. * end of the media is reached.
  631. */
  632. /**
  633. * Set the value of `mediaGroup` on the swf.
  634. *
  635. * @method Flash#setMediaGroup
  636. * @param {string} mediaGroup
  637. * New value of `mediaGroup` to set on the swf.
  638. */
  639. /**
  640. * Set the value of `controller` on the swf.
  641. *
  642. * @method Flash#setController
  643. * @param {string} controller
  644. * New value the current value of `controller` on the swf.
  645. */
  646. /**
  647. * Get the value of `controls` from the swf. `controls` indicates
  648. * whether the native flash controls should be shown or hidden.
  649. *
  650. * @method Flash#controls
  651. * @return {boolean}
  652. * - The value of `controls` from the swf.
  653. * - True indicates that native controls should be showing.
  654. * - False indicates that native controls should be hidden.
  655. */
  656. /**
  657. * Set the value of the `volume` on the swf. `volume` indicates the current
  658. * audio level as a percentage in decimal form. This means that 1 is 100%, 0.5 is 50%, and
  659. * so on.
  660. *
  661. * @method Flash#setVolume
  662. * @param {number} percentAsDecimal
  663. * The volume percent as a decimal. Value will be between 0-1.
  664. */
  665. /**
  666. * Set the value of the `muted` on the swf. `muted` indicates that the current
  667. * audio level should be silent.
  668. *
  669. * @method Flash#setMuted
  670. * @param {boolean} muted
  671. * - True if the audio should be set to silent
  672. * - False otherwise
  673. */
  674. /**
  675. * Set the value of `defaultMuted` on the swf. `defaultMuted` indicates
  676. * whether the media should start muted or not. Only changes the default state of the
  677. * media. `muted` and `defaultMuted` can have different values. `muted` indicates the
  678. * current state.
  679. *
  680. * @method Flash#setDefaultMuted
  681. * @param {boolean} defaultMuted
  682. * - True indicates that the media should start muted.
  683. * - False indicates that the media should not start muted.
  684. */
  685. /* Flash Support Testing -------------------------------------------------------- */
  686. /**
  687. * Check if the Flash tech is currently supported.
  688. *
  689. * @return {boolean}
  690. * - True if the flash tech is supported.
  691. * - False otherwise.
  692. */
  693. Flash.isSupported = function () {
  694. return Flash.version()[0] >= 10;
  695. // return swfobject.hasFlashPlayerVersion('10');
  696. };
  697. // Add Source Handler pattern functions to this tech
  698. _tech2['default'].withSourceHandlers(Flash);
  699. /*
  700. * Native source handler for flash, simply passes the source to the swf element.
  701. *
  702. * @property {Tech~SourceObject} source
  703. * The source object
  704. *
  705. * @property {Flash} tech
  706. * The instance of the Flash tech
  707. */
  708. Flash.nativeSourceHandler = {};
  709. /**
  710. * Check if the Flash can play the given mime type.
  711. *
  712. * @param {string} type
  713. * The mimetype to check
  714. *
  715. * @return {string}
  716. * 'maybe', or '' (empty string)
  717. */
  718. Flash.nativeSourceHandler.canPlayType = function (type) {
  719. if (type in Flash.formats) {
  720. return 'maybe';
  721. }
  722. return '';
  723. };
  724. /**
  725. * Check if the media element can handle a source natively.
  726. *
  727. * @param {Tech~SourceObject} source
  728. * The source object
  729. *
  730. * @param {Object} [options]
  731. * Options to be passed to the tech.
  732. *
  733. * @return {string}
  734. * 'maybe', or '' (empty string).
  735. */
  736. Flash.nativeSourceHandler.canHandleSource = function (source, options) {
  737. var type = void 0;
  738. function guessMimeType(src) {
  739. var ext = Url.getFileExtension(src);
  740. if (ext) {
  741. return 'video/' + ext;
  742. }
  743. return '';
  744. }
  745. if (!source.type) {
  746. type = guessMimeType(source.src);
  747. } else {
  748. // Strip code information from the type because we don't get that specific
  749. type = source.type.replace(/;.*/, '').toLowerCase();
  750. }
  751. return Flash.nativeSourceHandler.canPlayType(type);
  752. };
  753. /**
  754. * Pass the source to the swf.
  755. *
  756. * @param {Tech~SourceObject} source
  757. * The source object
  758. *
  759. * @param {Flash} tech
  760. * The instance of the Flash tech
  761. *
  762. * @param {Object} [options]
  763. * The options to pass to the source
  764. */
  765. Flash.nativeSourceHandler.handleSource = function (source, tech, options) {
  766. tech.setSrc(source.src);
  767. };
  768. /**
  769. * noop for native source handler dispose, as cleanup will happen automatically.
  770. */
  771. Flash.nativeSourceHandler.dispose = function () {};
  772. // Register the native source handler
  773. Flash.registerSourceHandler(Flash.nativeSourceHandler);
  774. /**
  775. * Flash supported mime types.
  776. *
  777. * @constant {Object}
  778. */
  779. Flash.formats = {
  780. 'video/flv': 'FLV',
  781. 'video/x-flv': 'FLV',
  782. 'video/mp4': 'MP4',
  783. 'video/m4v': 'MP4'
  784. };
  785. /**
  786. * Called when the the swf is "ready", and makes sure that the swf is really
  787. * ready using {@link Flash#checkReady}
  788. */
  789. Flash.onReady = function (currSwf) {
  790. var el = Dom.getEl(currSwf);
  791. var tech = el && el.tech;
  792. // if there is no el then the tech has been disposed
  793. // and the tech element was removed from the player div
  794. if (tech && tech.el()) {
  795. // check that the flash object is really ready
  796. Flash.checkReady(tech);
  797. }
  798. };
  799. /**
  800. * The SWF isn't always ready when it says it is. Sometimes the API functions still
  801. * need to be added to the object. If it's not ready, we set a timeout to check again
  802. * shortly.
  803. *
  804. * @param {Flash} tech
  805. * The instance of the flash tech to check.
  806. */
  807. Flash.checkReady = function (tech) {
  808. // stop worrying if the tech has been disposed
  809. if (!tech.el()) {
  810. return;
  811. }
  812. // check if API property exists
  813. if (tech.el().vjs_getProperty) {
  814. // tell tech it's ready
  815. tech.triggerReady();
  816. } else {
  817. // wait longer
  818. this.setTimeout(function () {
  819. Flash.checkReady(tech);
  820. }, 50);
  821. }
  822. };
  823. /**
  824. * Trigger events from the swf on the Flash Tech.
  825. *
  826. * @param {number} swfID
  827. * The id of the swf that had the event
  828. *
  829. * @param {string} eventName
  830. * The name of the event to trigger
  831. */
  832. Flash.onEvent = function (swfID, eventName) {
  833. var tech = Dom.getEl(swfID).tech;
  834. var args = Array.prototype.slice.call(arguments, 2);
  835. // dispatch Flash events asynchronously for two reasons:
  836. // - Flash swallows any exceptions generated by javascript it
  837. // invokes
  838. // - Flash is suspended until the javascript returns which may cause
  839. // playback performance issues
  840. tech.setTimeout(function () {
  841. tech.trigger(eventName, args);
  842. }, 1);
  843. };
  844. /**
  845. * Log errors from the swf on the Flash tech.
  846. *
  847. * @param {number} swfID
  848. * The id of the swf that had an error.
  849. *
  850. * @param {string} The error string
  851. * The error to set on the Flash Tech.
  852. *
  853. * @return {MediaError|undefined}
  854. * - Returns a MediaError when err is 'srcnotfound'
  855. * - Returns undefined otherwise.
  856. */
  857. Flash.onError = function (swfID, err) {
  858. var tech = Dom.getEl(swfID).tech;
  859. // trigger MEDIA_ERR_SRC_NOT_SUPPORTED
  860. if (err === 'srcnotfound') {
  861. return tech.error(4);
  862. }
  863. // trigger a custom error
  864. tech.error('FLASH: ' + err);
  865. };
  866. /**
  867. * Get the current version of Flash that is in use on the page.
  868. *
  869. * @return {Array}
  870. * an array of versions that are available.
  871. */
  872. Flash.version = function () {
  873. var version = '0,0,0';
  874. // IE
  875. try {
  876. version = new _window2['default'].ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
  877. // other browsers
  878. } catch (e) {
  879. try {
  880. if (navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
  881. version = (navigator.plugins['Shockwave Flash 2.0'] || navigator.plugins['Shockwave Flash']).description.replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
  882. }
  883. } catch (err) {
  884. // satisfy linter
  885. }
  886. }
  887. return version.split(',');
  888. };
  889. /**
  890. * Only use for non-iframe embeds.
  891. *
  892. * @param {Object} swf
  893. * The videojs-swf object.
  894. *
  895. * @param {Object} flashVars
  896. * Names and values to use as flash option variables.
  897. *
  898. * @param {Object} params
  899. * Style parameters to set on the object.
  900. *
  901. * @param {Object} attributes
  902. * Attributes to set on the element.
  903. *
  904. * @return {Element}
  905. * The embeded Flash DOM element.
  906. */
  907. Flash.embed = function (swf, flashVars, params, attributes) {
  908. var code = Flash.getEmbedCode(swf, flashVars, params, attributes);
  909. // Get element by embedding code and retrieving created element
  910. var obj = Dom.createEl('div', { innerHTML: code }).childNodes[0];
  911. return obj;
  912. };
  913. /**
  914. * Only use for non-iframe embeds.
  915. *
  916. * @param {Object} swf
  917. * The videojs-swf object.
  918. *
  919. * @param {Object} flashVars
  920. * Names and values to use as flash option variables.
  921. *
  922. * @param {Object} params
  923. * Style parameters to set on the object.
  924. *
  925. * @param {Object} attributes
  926. * Attributes to set on the element.
  927. *
  928. * @return {Element}
  929. * The embeded Flash DOM element.
  930. */
  931. Flash.getEmbedCode = function (swf, flashVars, params, attributes) {
  932. var objTag = '<object type="application/x-shockwave-flash" ';
  933. var flashVarsString = '';
  934. var paramsString = '';
  935. var attrsString = '';
  936. // Convert flash vars to string
  937. if (flashVars) {
  938. Object.getOwnPropertyNames(flashVars).forEach(function (key) {
  939. flashVarsString += key + '=' + flashVars[key] + '&amp;';
  940. });
  941. }
  942. // Add swf, flashVars, and other default params
  943. params = (0, _obj.assign)({
  944. movie: swf,
  945. flashvars: flashVarsString,
  946. // Required to talk to swf
  947. allowScriptAccess: 'always',
  948. // All should be default, but having security issues.
  949. allowNetworking: 'all'
  950. }, params);
  951. // Create param tags string
  952. Object.getOwnPropertyNames(params).forEach(function (key) {
  953. paramsString += '<param name="' + key + '" value="' + params[key] + '" />';
  954. });
  955. attributes = (0, _obj.assign)({
  956. // Add swf to attributes (need both for IE and Others to work)
  957. data: swf,
  958. // Default to 100% width/height
  959. width: '100%',
  960. height: '100%'
  961. }, attributes);
  962. // Create Attributes string
  963. Object.getOwnPropertyNames(attributes).forEach(function (key) {
  964. attrsString += key + '="' + attributes[key] + '" ';
  965. });
  966. return '' + objTag + attrsString + '>' + paramsString + '</object>';
  967. };
  968. // Run Flash through the RTMP decorator
  969. (0, _flashRtmp2['default'])(Flash);
  970. _component2['default'].registerComponent('Flash', Flash);
  971. _tech2['default'].registerTech('Flash', Flash);
  972. exports['default'] = Flash;