2
0

videojs-media-session.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.videojsMediaSession = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. (function (process){
  3. // Copyright Joyent, Inc. and other Node contributors.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the
  7. // "Software"), to deal in the Software without restriction, including
  8. // without limitation the rights to use, copy, modify, merge, publish,
  9. // distribute, sublicense, and/or sell copies of the Software, and to permit
  10. // persons to whom the Software is furnished to do so, subject to the
  11. // following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included
  14. // in all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  19. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  20. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  22. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. // resolves . and .. elements in a path array with directory names there
  24. // must be no slashes, empty elements, or device names (c:\) in the array
  25. // (so also no leading and trailing slashes - it does not distinguish
  26. // relative and absolute paths)
  27. function normalizeArray(parts, allowAboveRoot) {
  28. // if the path tries to go above the root, `up` ends up > 0
  29. var up = 0;
  30. for (var i = parts.length - 1; i >= 0; i--) {
  31. var last = parts[i];
  32. if (last === '.') {
  33. parts.splice(i, 1);
  34. } else if (last === '..') {
  35. parts.splice(i, 1);
  36. up++;
  37. } else if (up) {
  38. parts.splice(i, 1);
  39. up--;
  40. }
  41. }
  42. // if the path is allowed to go above the root, restore leading ..s
  43. if (allowAboveRoot) {
  44. for (; up--; up) {
  45. parts.unshift('..');
  46. }
  47. }
  48. return parts;
  49. }
  50. // Split a filename into [root, dir, basename, ext], unix version
  51. // 'root' is just a slash, or nothing.
  52. var splitPathRe =
  53. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  54. var splitPath = function(filename) {
  55. return splitPathRe.exec(filename).slice(1);
  56. };
  57. // path.resolve([from ...], to)
  58. // posix version
  59. exports.resolve = function() {
  60. var resolvedPath = '',
  61. resolvedAbsolute = false;
  62. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  63. var path = (i >= 0) ? arguments[i] : process.cwd();
  64. // Skip empty and invalid entries
  65. if (typeof path !== 'string') {
  66. throw new TypeError('Arguments to path.resolve must be strings');
  67. } else if (!path) {
  68. continue;
  69. }
  70. resolvedPath = path + '/' + resolvedPath;
  71. resolvedAbsolute = path.charAt(0) === '/';
  72. }
  73. // At this point the path should be resolved to a full absolute path, but
  74. // handle relative paths to be safe (might happen when process.cwd() fails)
  75. // Normalize the path
  76. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  77. return !!p;
  78. }), !resolvedAbsolute).join('/');
  79. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  80. };
  81. // path.normalize(path)
  82. // posix version
  83. exports.normalize = function(path) {
  84. var isAbsolute = exports.isAbsolute(path),
  85. trailingSlash = substr(path, -1) === '/';
  86. // Normalize the path
  87. path = normalizeArray(filter(path.split('/'), function(p) {
  88. return !!p;
  89. }), !isAbsolute).join('/');
  90. if (!path && !isAbsolute) {
  91. path = '.';
  92. }
  93. if (path && trailingSlash) {
  94. path += '/';
  95. }
  96. return (isAbsolute ? '/' : '') + path;
  97. };
  98. // posix version
  99. exports.isAbsolute = function(path) {
  100. return path.charAt(0) === '/';
  101. };
  102. // posix version
  103. exports.join = function() {
  104. var paths = Array.prototype.slice.call(arguments, 0);
  105. return exports.normalize(filter(paths, function(p, index) {
  106. if (typeof p !== 'string') {
  107. throw new TypeError('Arguments to path.join must be strings');
  108. }
  109. return p;
  110. }).join('/'));
  111. };
  112. // path.relative(from, to)
  113. // posix version
  114. exports.relative = function(from, to) {
  115. from = exports.resolve(from).substr(1);
  116. to = exports.resolve(to).substr(1);
  117. function trim(arr) {
  118. var start = 0;
  119. for (; start < arr.length; start++) {
  120. if (arr[start] !== '') break;
  121. }
  122. var end = arr.length - 1;
  123. for (; end >= 0; end--) {
  124. if (arr[end] !== '') break;
  125. }
  126. if (start > end) return [];
  127. return arr.slice(start, end - start + 1);
  128. }
  129. var fromParts = trim(from.split('/'));
  130. var toParts = trim(to.split('/'));
  131. var length = Math.min(fromParts.length, toParts.length);
  132. var samePartsLength = length;
  133. for (var i = 0; i < length; i++) {
  134. if (fromParts[i] !== toParts[i]) {
  135. samePartsLength = i;
  136. break;
  137. }
  138. }
  139. var outputParts = [];
  140. for (var i = samePartsLength; i < fromParts.length; i++) {
  141. outputParts.push('..');
  142. }
  143. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  144. return outputParts.join('/');
  145. };
  146. exports.sep = '/';
  147. exports.delimiter = ':';
  148. exports.dirname = function(path) {
  149. var result = splitPath(path),
  150. root = result[0],
  151. dir = result[1];
  152. if (!root && !dir) {
  153. // No dirname whatsoever
  154. return '.';
  155. }
  156. if (dir) {
  157. // It has a dirname, strip trailing slash
  158. dir = dir.substr(0, dir.length - 1);
  159. }
  160. return root + dir;
  161. };
  162. exports.basename = function(path, ext) {
  163. var f = splitPath(path)[2];
  164. // TODO: make this comparison case-insensitive on windows?
  165. if (ext && f.substr(-1 * ext.length) === ext) {
  166. f = f.substr(0, f.length - ext.length);
  167. }
  168. return f;
  169. };
  170. exports.extname = function(path) {
  171. return splitPath(path)[3];
  172. };
  173. function filter (xs, f) {
  174. if (xs.filter) return xs.filter(f);
  175. var res = [];
  176. for (var i = 0; i < xs.length; i++) {
  177. if (f(xs[i], i, xs)) res.push(xs[i]);
  178. }
  179. return res;
  180. }
  181. // String.prototype.substr - negative index don't work in IE8
  182. var substr = 'ab'.substr(-1) === 'b'
  183. ? function (str, start, len) { return str.substr(start, len) }
  184. : function (str, start, len) {
  185. if (start < 0) start = str.length + start;
  186. return str.substr(start, len);
  187. }
  188. ;
  189. }).call(this,require(2))
  190. },{"2":2}],2:[function(require,module,exports){
  191. // shim for using process in browser
  192. var process = module.exports = {};
  193. // cached from whatever global is present so that test runners that stub it
  194. // don't break things. But we need to wrap it in a try catch in case it is
  195. // wrapped in strict mode code which doesn't define any globals. It's inside a
  196. // function because try/catches deoptimize in certain engines.
  197. var cachedSetTimeout;
  198. var cachedClearTimeout;
  199. function defaultSetTimout() {
  200. throw new Error('setTimeout has not been defined');
  201. }
  202. function defaultClearTimeout () {
  203. throw new Error('clearTimeout has not been defined');
  204. }
  205. (function () {
  206. try {
  207. if (typeof setTimeout === 'function') {
  208. cachedSetTimeout = setTimeout;
  209. } else {
  210. cachedSetTimeout = defaultSetTimout;
  211. }
  212. } catch (e) {
  213. cachedSetTimeout = defaultSetTimout;
  214. }
  215. try {
  216. if (typeof clearTimeout === 'function') {
  217. cachedClearTimeout = clearTimeout;
  218. } else {
  219. cachedClearTimeout = defaultClearTimeout;
  220. }
  221. } catch (e) {
  222. cachedClearTimeout = defaultClearTimeout;
  223. }
  224. } ())
  225. function runTimeout(fun) {
  226. if (cachedSetTimeout === setTimeout) {
  227. //normal enviroments in sane situations
  228. return setTimeout(fun, 0);
  229. }
  230. // if setTimeout wasn't available but was latter defined
  231. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  232. cachedSetTimeout = setTimeout;
  233. return setTimeout(fun, 0);
  234. }
  235. try {
  236. // when when somebody has screwed with setTimeout but no I.E. maddness
  237. return cachedSetTimeout(fun, 0);
  238. } catch(e){
  239. try {
  240. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  241. return cachedSetTimeout.call(null, fun, 0);
  242. } catch(e){
  243. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  244. return cachedSetTimeout.call(this, fun, 0);
  245. }
  246. }
  247. }
  248. function runClearTimeout(marker) {
  249. if (cachedClearTimeout === clearTimeout) {
  250. //normal enviroments in sane situations
  251. return clearTimeout(marker);
  252. }
  253. // if clearTimeout wasn't available but was latter defined
  254. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  255. cachedClearTimeout = clearTimeout;
  256. return clearTimeout(marker);
  257. }
  258. try {
  259. // when when somebody has screwed with setTimeout but no I.E. maddness
  260. return cachedClearTimeout(marker);
  261. } catch (e){
  262. try {
  263. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  264. return cachedClearTimeout.call(null, marker);
  265. } catch (e){
  266. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  267. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  268. return cachedClearTimeout.call(this, marker);
  269. }
  270. }
  271. }
  272. var queue = [];
  273. var draining = false;
  274. var currentQueue;
  275. var queueIndex = -1;
  276. function cleanUpNextTick() {
  277. if (!draining || !currentQueue) {
  278. return;
  279. }
  280. draining = false;
  281. if (currentQueue.length) {
  282. queue = currentQueue.concat(queue);
  283. } else {
  284. queueIndex = -1;
  285. }
  286. if (queue.length) {
  287. drainQueue();
  288. }
  289. }
  290. function drainQueue() {
  291. if (draining) {
  292. return;
  293. }
  294. var timeout = runTimeout(cleanUpNextTick);
  295. draining = true;
  296. var len = queue.length;
  297. while(len) {
  298. currentQueue = queue;
  299. queue = [];
  300. while (++queueIndex < len) {
  301. if (currentQueue) {
  302. currentQueue[queueIndex].run();
  303. }
  304. }
  305. queueIndex = -1;
  306. len = queue.length;
  307. }
  308. currentQueue = null;
  309. draining = false;
  310. runClearTimeout(timeout);
  311. }
  312. process.nextTick = function (fun) {
  313. var args = new Array(arguments.length - 1);
  314. if (arguments.length > 1) {
  315. for (var i = 1; i < arguments.length; i++) {
  316. args[i - 1] = arguments[i];
  317. }
  318. }
  319. queue.push(new Item(fun, args));
  320. if (queue.length === 1 && !draining) {
  321. runTimeout(drainQueue);
  322. }
  323. };
  324. // v8 likes predictible objects
  325. function Item(fun, array) {
  326. this.fun = fun;
  327. this.array = array;
  328. }
  329. Item.prototype.run = function () {
  330. this.fun.apply(null, this.array);
  331. };
  332. process.title = 'browser';
  333. process.browser = true;
  334. process.env = {};
  335. process.argv = [];
  336. process.version = ''; // empty string to avoid regexp issues
  337. process.versions = {};
  338. function noop() {}
  339. process.on = noop;
  340. process.addListener = noop;
  341. process.once = noop;
  342. process.off = noop;
  343. process.removeListener = noop;
  344. process.removeAllListeners = noop;
  345. process.emit = noop;
  346. process.binding = function (name) {
  347. throw new Error('process.binding is not supported');
  348. };
  349. process.cwd = function () { return '/' };
  350. process.chdir = function (dir) {
  351. throw new Error('process.chdir is not supported');
  352. };
  353. process.umask = function() { return 0; };
  354. },{}],3:[function(require,module,exports){
  355. (function (global){
  356. 'use strict';
  357. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  358. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  359. function _interopDefault(ex) {
  360. return ex && (typeof ex === 'undefined' ? 'undefined' : _typeof(ex)) === 'object' && 'default' in ex ? ex['default'] : ex;
  361. }
  362. var videojs = _interopDefault((typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null));
  363. var path = _interopDefault(require(1));
  364. // Default options for the plugin.
  365. var defaults = {};
  366. // Cross-compatibility for Video.js 5 and 6.
  367. var registerPlugin = videojs.registerPlugin || videojs.plugin;
  368. // const dom = videojs.dom || videojs;
  369. var MEDIA_SESSION_EXISTS = Boolean(navigator.mediaSession);
  370. var SKIP_TIME = 10;
  371. /**
  372. * Function to invoke when the player is ready.
  373. *
  374. * This is a great place for your plugin to initialize itself. When this
  375. * function is called, the player will have its DOM and child components
  376. * in place.
  377. *
  378. * @function onPlayerReady
  379. * @param {Player} player
  380. * A Video.js player.
  381. * @param {Object} [options={}]
  382. * An object of options left to the plugin author to define.
  383. */
  384. var onPlayerReady = function onPlayerReady(player, options) {
  385. if (!MEDIA_SESSION_EXISTS) {
  386. videojs.log.warn('Media Session is not available on this device.\n Please try Chrome for Android 57');
  387. return;
  388. }
  389. setUpSkips(player);
  390. if (player.playlist) {
  391. setUpPlaylist(player);
  392. }
  393. player.on('loadstart', function () {
  394. return updateMediaSession(player);
  395. });
  396. updateMediaSession(player);
  397. player.addClass('vjs-media-session');
  398. };
  399. var updateMediaSession = function updateMediaSession(player) {
  400. var curSrc = void 0;
  401. if (player.playlist) {
  402. var playlist = player.playlist();
  403. curSrc = _extends({}, playlist[player.playlist.currentItem()]);
  404. } else {
  405. curSrc = _extends({}, player.currentSource());
  406. }
  407. curSrc.title = curSrc.name;
  408. if (!curSrc.artwork) {
  409. var poster = player.poster();
  410. if (curSrc.thumbnail) {
  411. curSrc.artwork = curSrc.thumbnail.map(function (thumb) {
  412. return {
  413. src: thumb.srcset || thumb.src,
  414. type: thumb.type || path.extname(thumb.src).slice(1)
  415. };
  416. });
  417. } else if (poster) {
  418. curSrc.artwork = [{
  419. src: poster,
  420. type: 'image/' + path.extname(poster).slice(1)
  421. }];
  422. }
  423. }
  424. curSrc.src = player.currentSrc();
  425. navigator.mediaSession.metadata = new MediaMetadata(curSrc);
  426. };
  427. var setUpSkips = function setUpSkips(player) {
  428. navigator.mediaSession.setActionHandler('seekbackward', function () {
  429. player.currentTime(player.currentTime() - SKIP_TIME);
  430. });
  431. navigator.mediaSession.setActionHandler('seekforward', function () {
  432. player.currentTime(player.currentTime() + SKIP_TIME);
  433. });
  434. };
  435. var setUpPlaylist = function setUpPlaylist(player) {
  436. navigator.mediaSession.setActionHandler('previoustrack', function () {
  437. player.playlist.previous();
  438. });
  439. navigator.mediaSession.setActionHandler('nexttrack', function () {
  440. player.playlist.next();
  441. });
  442. };
  443. /**
  444. * A video.js plugin.
  445. *
  446. * In the plugin function, the value of `this` is a video.js `Player`
  447. * instance. You cannot rely on the player being in a "ready" state here,
  448. * depending on how the plugin is invoked. This may or may not be important
  449. * to you; if not, remove the wait for "ready"!
  450. *
  451. * @function mediaSession
  452. * @param {Object} [options={}]
  453. * An object of options left to the plugin author to define.
  454. */
  455. var mediaSession = function mediaSession(options) {
  456. var _this = this;
  457. this.ready(function () {
  458. onPlayerReady(_this, videojs.mergeOptions(defaults, options));
  459. });
  460. };
  461. // Register the plugin with video.js.
  462. registerPlugin('mediaSession', mediaSession);
  463. // Include the version number.
  464. mediaSession.VERSION = '1.0.0';
  465. module.exports = mediaSession;
  466. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  467. },{"1":1}]},{},[3])(3)
  468. });
  469. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy92aWRlb2pzLXNwZWxsYm9vay9ub2RlX21vZHVsZXMvYnJvd3NlcmlmeS9ub2RlX21vZHVsZXMvYnJvd3Nlci1wYWNrL19wcmVsdWRlLmpzIiwibm9kZV9tb2R1bGVzL3ZpZGVvanMtc3BlbGxib29rL25vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9wYXRoLWJyb3dzZXJpZnkvaW5kZXguanMiLCJub2RlX21vZHVsZXMvdmlkZW9qcy1zcGVsbGJvb2svbm9kZV9tb2R1bGVzL2Jyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL3Byb2Nlc3MvYnJvd3Nlci5qcyIsInNyYy9qcy9pbmRleC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7QUNBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FB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