UNPKG

yl-vjs-player-sdk

Version:

云粒 videojs 视频播放器 SDK

1,568 lines (1,297 loc) 216 kB
/** * @license * yunli-vjs-player.js 0.0.45 <https://yunlizhihui.com> * Copyright Yunlizhihui, Inc. <https://yunlizhihui.com> * Available under Apache License Version 2.0 */ import videojs from 'video.js'; var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function unwrapExports (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } function getCjsExportFromNamespace (n) { return n && n['default'] || n; } var check = function (it) { return it && it.Math == Math && it; }; // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 var global_1 = // eslint-disable-next-line es/no-global-this -- safe check(typeof globalThis == 'object' && globalThis) || check(typeof window == 'object' && window) || // eslint-disable-next-line no-restricted-globals -- safe check(typeof self == 'object' && self) || check(typeof commonjsGlobal == 'object' && commonjsGlobal) || // eslint-disable-next-line no-new-func -- fallback (function () { return this; })() || Function('return this')(); var fails = function (exec) { try { return !!exec(); } catch (error) { return true; } }; // Detect IE8's incomplete defineProperty implementation var descriptors = !fails(function () { // eslint-disable-next-line es/no-object-defineproperty -- required for testing return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7; }); var $propertyIsEnumerable = {}.propertyIsEnumerable; // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; // Nashorn ~ JDK8 bug var NASHORN_BUG = getOwnPropertyDescriptor && !$propertyIsEnumerable.call({ 1: 2 }, 1); // `Object.prototype.propertyIsEnumerable` method implementation // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable var f = NASHORN_BUG ? function propertyIsEnumerable(V) { var descriptor = getOwnPropertyDescriptor(this, V); return !!descriptor && descriptor.enumerable; } : $propertyIsEnumerable; var objectPropertyIsEnumerable = { f: f }; var createPropertyDescriptor = function (bitmap, value) { return { enumerable: !(bitmap & 1), configurable: !(bitmap & 2), writable: !(bitmap & 4), value: value }; }; var toString = {}.toString; var classofRaw = function (it) { return toString.call(it).slice(8, -1); }; var split = ''.split; // fallback for non-array-like ES3 and non-enumerable old V8 strings var indexedObject = fails(function () { // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346 // eslint-disable-next-line no-prototype-builtins -- safe return !Object('z').propertyIsEnumerable(0); }) ? function (it) { return classofRaw(it) == 'String' ? split.call(it, '') : Object(it); } : Object; // `RequireObjectCoercible` abstract operation // https://tc39.es/ecma262/#sec-requireobjectcoercible var requireObjectCoercible = function (it) { if (it == undefined) throw TypeError("Can't call method on " + it); return it; }; // toObject with fallback for non-array-like ES3 strings var toIndexedObject = function (it) { return indexedObject(requireObjectCoercible(it)); }; var isObject = function (it) { return typeof it === 'object' ? it !== null : typeof it === 'function'; }; var path = {}; var aFunction = function (variable) { return typeof variable == 'function' ? variable : undefined; }; var getBuiltIn = function (namespace, method) { return arguments.length < 2 ? aFunction(path[namespace]) || aFunction(global_1[namespace]) : path[namespace] && path[namespace][method] || global_1[namespace] && global_1[namespace][method]; }; var engineUserAgent = getBuiltIn('navigator', 'userAgent') || ''; var process = global_1.process; var Deno = global_1.Deno; var versions = process && process.versions || Deno && Deno.version; var v8 = versions && versions.v8; var match, version; if (v8) { match = v8.split('.'); version = match[0] < 4 ? 1 : match[0] + match[1]; } else if (engineUserAgent) { match = engineUserAgent.match(/Edge\/(\d+)/); if (!match || match[1] >= 74) { match = engineUserAgent.match(/Chrome\/(\d+)/); if (match) version = match[1]; } } var engineV8Version = version && +version; /* eslint-disable es/no-symbol -- required for testing */ // eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing var nativeSymbol = !!Object.getOwnPropertySymbols && !fails(function () { var symbol = Symbol(); // Chrome 38 Symbol has incorrect toString conversion // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances return !String(symbol) || !(Object(symbol) instanceof Symbol) || // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances !Symbol.sham && engineV8Version && engineV8Version < 41; }); /* eslint-disable es/no-symbol -- required for testing */ var useSymbolAsUid = nativeSymbol && !Symbol.sham && typeof Symbol.iterator == 'symbol'; var isSymbol = useSymbolAsUid ? function (it) { return typeof it == 'symbol'; } : function (it) { var $Symbol = getBuiltIn('Symbol'); return typeof $Symbol == 'function' && Object(it) instanceof $Symbol; }; // `OrdinaryToPrimitive` abstract operation // https://tc39.es/ecma262/#sec-ordinarytoprimitive var ordinaryToPrimitive = function (input, pref) { var fn, val; if (pref === 'string' && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val; if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val; if (pref !== 'string' && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val; throw TypeError("Can't convert object to primitive value"); }; var isPure = true; var setGlobal = function (key, value) { try { // eslint-disable-next-line es/no-object-defineproperty -- safe Object.defineProperty(global_1, key, { value: value, configurable: true, writable: true }); } catch (error) { global_1[key] = value; } return value; }; var SHARED = '__core-js_shared__'; var store = global_1[SHARED] || setGlobal(SHARED, {}); var sharedStore = store; var shared = createCommonjsModule(function (module) { (module.exports = function (key, value) { return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {}); })('versions', []).push({ version: '3.16.3', mode: 'pure' , copyright: '© 2021 Denis Pushkarev (zloirock.ru)' }); }); // `ToObject` abstract operation // https://tc39.es/ecma262/#sec-toobject var toObject = function (argument) { return Object(requireObjectCoercible(argument)); }; var hasOwnProperty = {}.hasOwnProperty; var has = Object.hasOwn || function hasOwn(it, key) { return hasOwnProperty.call(toObject(it), key); }; var id = 0; var postfix = Math.random(); var uid = function (key) { return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36); }; var WellKnownSymbolsStore = shared('wks'); var Symbol$1 = global_1.Symbol; var createWellKnownSymbol = useSymbolAsUid ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid; var wellKnownSymbol = function (name) { if (!has(WellKnownSymbolsStore, name) || !(nativeSymbol || typeof WellKnownSymbolsStore[name] == 'string')) { if (nativeSymbol && has(Symbol$1, name)) { WellKnownSymbolsStore[name] = Symbol$1[name]; } else { WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name); } } return WellKnownSymbolsStore[name]; }; var TO_PRIMITIVE = wellKnownSymbol('toPrimitive'); // `ToPrimitive` abstract operation // https://tc39.es/ecma262/#sec-toprimitive var toPrimitive = function (input, pref) { if (!isObject(input) || isSymbol(input)) return input; var exoticToPrim = input[TO_PRIMITIVE]; var result; if (exoticToPrim !== undefined) { if (pref === undefined) pref = 'default'; result = exoticToPrim.call(input, pref); if (!isObject(result) || isSymbol(result)) return result; throw TypeError("Can't convert object to primitive value"); } if (pref === undefined) pref = 'number'; return ordinaryToPrimitive(input, pref); }; // `ToPropertyKey` abstract operation // https://tc39.es/ecma262/#sec-topropertykey var toPropertyKey = function (argument) { var key = toPrimitive(argument, 'string'); return isSymbol(key) ? key : String(key); }; var document$1 = global_1.document; // typeof document.createElement is 'object' in old IE var EXISTS = isObject(document$1) && isObject(document$1.createElement); var documentCreateElement = function (it) { return EXISTS ? document$1.createElement(it) : {}; }; // Thank's IE8 for his funny defineProperty var ie8DomDefine = !descriptors && !fails(function () { // eslint-disable-next-line es/no-object-defineproperty -- requied for testing return Object.defineProperty(documentCreateElement('div'), 'a', { get: function () { return 7; } }).a != 7; }); // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; // `Object.getOwnPropertyDescriptor` method // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor var f$1 = descriptors ? $getOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) { O = toIndexedObject(O); P = toPropertyKey(P); if (ie8DomDefine) try { return $getOwnPropertyDescriptor(O, P); } catch (error) { /* empty */ } if (has(O, P)) return createPropertyDescriptor(!objectPropertyIsEnumerable.f.call(O, P), O[P]); }; var objectGetOwnPropertyDescriptor = { f: f$1 }; var replacement = /#|\.prototype\./; var isForced = function (feature, detection) { var value = data[normalize(feature)]; return value == POLYFILL ? true : value == NATIVE ? false : typeof detection == 'function' ? fails(detection) : !!detection; }; var normalize = isForced.normalize = function (string) { return String(string).replace(replacement, '.').toLowerCase(); }; var data = isForced.data = {}; var NATIVE = isForced.NATIVE = 'N'; var POLYFILL = isForced.POLYFILL = 'P'; var isForced_1 = isForced; var aFunction$1 = function (it) { if (typeof it != 'function') { throw TypeError(String(it) + ' is not a function'); } return it; }; // optional / simple context binding var functionBindContext = function (fn, that, length) { aFunction$1(fn); if (that === undefined) return fn; switch (length) { case 0: return function () { return fn.call(that); }; case 1: return function (a) { return fn.call(that, a); }; case 2: return function (a, b) { return fn.call(that, a, b); }; case 3: return function (a, b, c) { return fn.call(that, a, b, c); }; } return function (/* ...args */) { return fn.apply(that, arguments); }; }; var anObject = function (it) { if (!isObject(it)) { throw TypeError(String(it) + ' is not an object'); } return it; }; // eslint-disable-next-line es/no-object-defineproperty -- safe var $defineProperty = Object.defineProperty; // `Object.defineProperty` method // https://tc39.es/ecma262/#sec-object.defineproperty var f$2 = descriptors ? $defineProperty : function defineProperty(O, P, Attributes) { anObject(O); P = toPropertyKey(P); anObject(Attributes); if (ie8DomDefine) try { return $defineProperty(O, P, Attributes); } catch (error) { /* empty */ } if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported'); if ('value' in Attributes) O[P] = Attributes.value; return O; }; var objectDefineProperty = { f: f$2 }; var createNonEnumerableProperty = descriptors ? function (object, key, value) { return objectDefineProperty.f(object, key, createPropertyDescriptor(1, value)); } : function (object, key, value) { object[key] = value; return object; }; var getOwnPropertyDescriptor$1 = objectGetOwnPropertyDescriptor.f; var wrapConstructor = function (NativeConstructor) { var Wrapper = function (a, b, c) { if (this instanceof NativeConstructor) { switch (arguments.length) { case 0: return new NativeConstructor(); case 1: return new NativeConstructor(a); case 2: return new NativeConstructor(a, b); } return new NativeConstructor(a, b, c); } return NativeConstructor.apply(this, arguments); }; Wrapper.prototype = NativeConstructor.prototype; return Wrapper; }; /* options.target - name of the target object options.global - target is the global object options.stat - export as static methods of target options.proto - export as prototype methods of target options.real - real prototype method for the `pure` version options.forced - export even if the native feature is available options.bind - bind methods to the target, required for the `pure` version options.wrap - wrap constructors to preventing global pollution, required for the `pure` version options.unsafe - use the simple assignment of property instead of delete + defineProperty options.sham - add a flag to not completely full polyfills options.enumerable - export as enumerable property options.noTargetGet - prevent calling a getter on target */ var _export = function (options, source) { var TARGET = options.target; var GLOBAL = options.global; var STATIC = options.stat; var PROTO = options.proto; var nativeSource = GLOBAL ? global_1 : STATIC ? global_1[TARGET] : (global_1[TARGET] || {}).prototype; var target = GLOBAL ? path : path[TARGET] || createNonEnumerableProperty(path, TARGET, {})[TARGET]; var targetPrototype = target.prototype; var FORCED, USE_NATIVE, VIRTUAL_PROTOTYPE; var key, sourceProperty, targetProperty, nativeProperty, resultProperty, descriptor; for (key in source) { FORCED = isForced_1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced); // contains in native USE_NATIVE = !FORCED && nativeSource && has(nativeSource, key); targetProperty = target[key]; if (USE_NATIVE) if (options.noTargetGet) { descriptor = getOwnPropertyDescriptor$1(nativeSource, key); nativeProperty = descriptor && descriptor.value; } else nativeProperty = nativeSource[key]; // export native or implementation sourceProperty = (USE_NATIVE && nativeProperty) ? nativeProperty : source[key]; if (USE_NATIVE && typeof targetProperty === typeof sourceProperty) continue; // bind timers to global for call from export context if (options.bind && USE_NATIVE) resultProperty = functionBindContext(sourceProperty, global_1); // wrap global constructors for prevent changs in this version else if (options.wrap && USE_NATIVE) resultProperty = wrapConstructor(sourceProperty); // make static versions for prototype methods else if (PROTO && typeof sourceProperty == 'function') resultProperty = functionBindContext(Function.call, sourceProperty); // default case else resultProperty = sourceProperty; // add a flag to not completely full polyfills if (options.sham || (sourceProperty && sourceProperty.sham) || (targetProperty && targetProperty.sham)) { createNonEnumerableProperty(resultProperty, 'sham', true); } createNonEnumerableProperty(target, key, resultProperty); if (PROTO) { VIRTUAL_PROTOTYPE = TARGET + 'Prototype'; if (!has(path, VIRTUAL_PROTOTYPE)) { createNonEnumerableProperty(path, VIRTUAL_PROTOTYPE, {}); } // export virtual prototype methods createNonEnumerableProperty(path[VIRTUAL_PROTOTYPE], key, sourceProperty); // export real prototype methods if (options.real && targetPrototype && !targetPrototype[key]) { createNonEnumerableProperty(targetPrototype, key, sourceProperty); } } } }; var ceil = Math.ceil; var floor = Math.floor; // `ToInteger` abstract operation // https://tc39.es/ecma262/#sec-tointeger var toInteger = function (argument) { return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor : ceil)(argument); }; var max = Math.max; var min = Math.min; // Helper for a popular repeating case of the spec: // Let integer be ? ToInteger(index). // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length). var toAbsoluteIndex = function (index, length) { var integer = toInteger(index); return integer < 0 ? max(integer + length, 0) : min(integer, length); }; var min$1 = Math.min; // `ToLength` abstract operation // https://tc39.es/ecma262/#sec-tolength var toLength = function (argument) { return argument > 0 ? min$1(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991 }; // `IsArray` abstract operation // https://tc39.es/ecma262/#sec-isarray // eslint-disable-next-line es/no-array-isarray -- safe var isArray = Array.isArray || function isArray(arg) { return classofRaw(arg) == 'Array'; }; var SPECIES = wellKnownSymbol('species'); // a part of `ArraySpeciesCreate` abstract operation // https://tc39.es/ecma262/#sec-arrayspeciescreate var arraySpeciesConstructor = function (originalArray) { var C; if (isArray(originalArray)) { C = originalArray.constructor; // cross-realm fallback if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined; else if (isObject(C)) { C = C[SPECIES]; if (C === null) C = undefined; } } return C === undefined ? Array : C; }; // `ArraySpeciesCreate` abstract operation // https://tc39.es/ecma262/#sec-arrayspeciescreate var arraySpeciesCreate = function (originalArray, length) { return new (arraySpeciesConstructor(originalArray))(length === 0 ? 0 : length); }; var createProperty = function (object, key, value) { var propertyKey = toPropertyKey(key); if (propertyKey in object) objectDefineProperty.f(object, propertyKey, createPropertyDescriptor(0, value)); else object[propertyKey] = value; }; var SPECIES$1 = wellKnownSymbol('species'); var arrayMethodHasSpeciesSupport = function (METHOD_NAME) { // We can't use this feature detection in V8 since it causes // deoptimization and serious performance degradation // https://github.com/zloirock/core-js/issues/677 return engineV8Version >= 51 || !fails(function () { var array = []; var constructor = array.constructor = {}; constructor[SPECIES$1] = function () { return { foo: 1 }; }; return array[METHOD_NAME](Boolean).foo !== 1; }); }; var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('splice'); var max$1 = Math.max; var min$2 = Math.min; var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; var MAXIMUM_ALLOWED_LENGTH_EXCEEDED = 'Maximum allowed length exceeded'; // `Array.prototype.splice` method // https://tc39.es/ecma262/#sec-array.prototype.splice // with adding support of @@species _export({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT }, { splice: function splice(start, deleteCount /* , ...items */) { var O = toObject(this); var len = toLength(O.length); var actualStart = toAbsoluteIndex(start, len); var argumentsLength = arguments.length; var insertCount, actualDeleteCount, A, k, from, to; if (argumentsLength === 0) { insertCount = actualDeleteCount = 0; } else if (argumentsLength === 1) { insertCount = 0; actualDeleteCount = len - actualStart; } else { insertCount = argumentsLength - 2; actualDeleteCount = min$2(max$1(toInteger(deleteCount), 0), len - actualStart); } if (len + insertCount - actualDeleteCount > MAX_SAFE_INTEGER) { throw TypeError(MAXIMUM_ALLOWED_LENGTH_EXCEEDED); } A = arraySpeciesCreate(O, actualDeleteCount); for (k = 0; k < actualDeleteCount; k++) { from = actualStart + k; if (from in O) createProperty(A, k, O[from]); } A.length = actualDeleteCount; if (insertCount < actualDeleteCount) { for (k = actualStart; k < len - actualDeleteCount; k++) { from = k + actualDeleteCount; to = k + insertCount; if (from in O) O[to] = O[from]; else delete O[to]; } for (k = len; k > len - actualDeleteCount + insertCount; k--) delete O[k - 1]; } else if (insertCount > actualDeleteCount) { for (k = len - actualDeleteCount; k > actualStart; k--) { from = k + actualDeleteCount - 1; to = k + insertCount - 1; if (from in O) O[to] = O[from]; else delete O[to]; } } for (k = 0; k < insertCount; k++) { O[k + actualStart] = arguments[k + 2]; } O.length = len - actualDeleteCount + insertCount; return A; } }); var entryVirtual = function (CONSTRUCTOR) { return path[CONSTRUCTOR + 'Prototype']; }; var splice = entryVirtual('Array').splice; var ArrayPrototype = Array.prototype; var splice_1 = function (it) { var own = it.splice; return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.splice) ? splice : own; }; var splice$1 = splice_1; var splice$2 = splice$1; var slice = [].slice; var MSIE = /MSIE .\./.test(engineUserAgent); // <- dirty ie9- check var wrap = function (scheduler) { return function (handler, timeout /* , ...arguments */) { var boundArgs = arguments.length > 2; var args = boundArgs ? slice.call(arguments, 2) : undefined; return scheduler(boundArgs ? function () { // eslint-disable-next-line no-new-func -- spec requirement (typeof handler == 'function' ? handler : Function(handler)).apply(this, args); } : handler, timeout); }; }; // ie9- setTimeout & setInterval additional parameters fix // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers _export({ global: true, bind: true, forced: MSIE }, { // `setTimeout` method // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-settimeout setTimeout: wrap(global_1.setTimeout), // `setInterval` method // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-setinterval setInterval: wrap(global_1.setInterval) }); var setTimeout = path.setTimeout; var setTimeout$1 = setTimeout; // `Array.prototype.{ indexOf, includes }` methods implementation var createMethod = function (IS_INCLUDES) { return function ($this, el, fromIndex) { var O = toIndexedObject($this); var length = toLength(O.length); var index = toAbsoluteIndex(fromIndex, length); var value; // Array#includes uses SameValueZero equality algorithm // eslint-disable-next-line no-self-compare -- NaN check if (IS_INCLUDES && el != el) while (length > index) { value = O[index++]; // eslint-disable-next-line no-self-compare -- NaN check if (value != value) return true; // Array#indexOf ignores holes, Array#includes - not } else for (;length > index; index++) { if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0; } return !IS_INCLUDES && -1; }; }; var arrayIncludes = { // `Array.prototype.includes` method // https://tc39.es/ecma262/#sec-array.prototype.includes includes: createMethod(true), // `Array.prototype.indexOf` method // https://tc39.es/ecma262/#sec-array.prototype.indexof indexOf: createMethod(false) }; var arrayMethodIsStrict = function (METHOD_NAME, argument) { var method = [][METHOD_NAME]; return !!method && fails(function () { // eslint-disable-next-line no-useless-call,no-throw-literal -- required for testing method.call(null, argument || function () { throw 1; }, 1); }); }; /* eslint-disable es/no-array-prototype-indexof -- required for testing */ var $indexOf = arrayIncludes.indexOf; var nativeIndexOf = [].indexOf; var NEGATIVE_ZERO = !!nativeIndexOf && 1 / [1].indexOf(1, -0) < 0; var STRICT_METHOD = arrayMethodIsStrict('indexOf'); // `Array.prototype.indexOf` method // https://tc39.es/ecma262/#sec-array.prototype.indexof _export({ target: 'Array', proto: true, forced: NEGATIVE_ZERO || !STRICT_METHOD }, { indexOf: function indexOf(searchElement /* , fromIndex = 0 */) { return NEGATIVE_ZERO // convert -0 to +0 ? nativeIndexOf.apply(this, arguments) || 0 : $indexOf(this, searchElement, arguments.length > 1 ? arguments[1] : undefined); } }); var indexOf = entryVirtual('Array').indexOf; var ArrayPrototype$1 = Array.prototype; var indexOf_1 = function (it) { var own = it.indexOf; return it === ArrayPrototype$1 || (it instanceof Array && own === ArrayPrototype$1.indexOf) ? indexOf : own; }; var indexOf$1 = indexOf_1; var indexOf$2 = indexOf$1; var Play = "播放"; var Pause = "暂停"; var Duration = "时长"; var LIVE = "直播"; var Loaded = "加载完成"; var Progress = "进度"; var Fullscreen = "全屏"; var Mute = "静音"; var Unmute = "取消静音"; var Subtitles = "字幕"; var Captions = "内嵌字幕"; var Chapters = "节目段落"; var Descriptions = "描述"; var Close = "关闭"; var Replay = "重新播放"; var Text = "文字"; var White = "白"; var Black = "黑"; var Red = "红"; var Green = "绿"; var Blue = "蓝"; var Yellow = "黄"; var Magenta = "紫红"; var Cyan = "青"; var Background = "背景"; var Window = "窗口"; var Transparent = "透明"; var Opaque = "不透明"; var None = "无"; var Raised = "浮雕"; var Depressed = "压低"; var Uniform = "均匀"; var Dropshadow = "下阴影"; var Casual = "舒适"; var Script = "手写体"; var Reset = "重置"; var Done = "完成"; var Snap = "截屏"; var Record = "录制"; var lang = { Play: Play, Pause: Pause, "Current Time": "当前时间", Duration: Duration, "Remaining Time": "剩余时间", "Stream Type": "媒体流类型", LIVE: LIVE, Loaded: Loaded, Progress: Progress, Fullscreen: Fullscreen, "Picture-in-Picture": "画中画", "Exit Picture-in-Picture": "退出画中画", "Non-Fullscreen": "退出全屏", Mute: Mute, Unmute: Unmute, "Playback Rate": "播放速度", Subtitles: Subtitles, "subtitles off": "关闭字幕", Captions: Captions, "captions off": "关闭内嵌字幕", Chapters: Chapters, "Close Modal Dialog": "关闭弹窗", Descriptions: Descriptions, "descriptions off": "关闭描述", "Audio Track": "音轨", "You aborted the media playback": "视频播放被终止", "A network error caused the media download to fail part-way.": "网络错误导致视频下载中途失败。", "The media could not be loaded, either because the server or network failed or because the format is not supported.": "视频因格式不支持或者服务器或网络的问题无法加载。", "The media playback was aborted due to a corruption problem or because the media used features your browser did not support.": "由于视频文件损坏或是该视频使用了你的浏览器不支持的功能,播放终止。", "No compatible source was found for this media.": "无法找到此视频兼容的源。", "The media is encrypted and we do not have the keys to decrypt it.": "视频已加密,无法解密。", "Play Video": "播放视频", Close: Close, "Modal Window": "弹窗", "This is a modal window": "这是一个弹窗", "This modal can be closed by pressing the Escape key or activating the close button.": "可以按ESC按键或启用关闭按钮来关闭此弹窗。", ", opens captions settings dialog": ", 开启标题设置弹窗", ", opens subtitles settings dialog": ", 开启字幕设置弹窗", ", opens descriptions settings dialog": ", 开启描述设置弹窗", ", selected": ", 选择", "captions settings": "字幕设定", "Audio Player": "音频播放器", "Video Player": "视频播放器", Replay: Replay, "Progress Bar": "进度条", "Volume Level": "音量", "subtitles settings": "字幕设定", "descriptions settings": "描述设定", Text: Text, White: White, Black: Black, Red: Red, Green: Green, Blue: Blue, Yellow: Yellow, Magenta: Magenta, Cyan: Cyan, Background: Background, Window: Window, Transparent: Transparent, "Semi-Transparent": "半透明", Opaque: Opaque, "Font Size": "字体尺寸", "Text Edge Style": "字体边缘样式", None: None, Raised: Raised, Depressed: Depressed, Uniform: Uniform, Dropshadow: Dropshadow, "Font Family": "字体库", "Proportional Sans-Serif": "比例无细体", "Monospace Sans-Serif": "单间隔无细体", "Proportional Serif": "比例细体", "Monospace Serif": "单间隔细体", Casual: Casual, Script: Script, "Small Caps": "小型大写字体", Reset: Reset, "restore all settings to the default values": "恢复全部设定至预设值", Done: Done, "Caption Settings Dialog": "字幕设定窗口", "Beginning of dialog window. Escape will cancel and close the window.": "打开对话窗口。Escape键将取消并关闭对话窗口", "End of dialog window.": "结束对话窗口", "Seek to live, currently behind live": "尝试直播,当前为延时播放", "Seek to live, currently playing live": "尝试直播,当前为实时播放", "progress bar timing: currentTime={1} duration={2}": "{1}/{2}", "{1} is loading.": "正在加载 {1}。", Snap: Snap, Record: Record, "Non-Record": "停止录制" }; function initMixin(YunliVjsPlayer) { YunliVjsPlayer.prototype._init = function (el, options, readyCallback) { //videojs对象 if (!videojs) { throw new Error('本组件依赖videojs库,请先引入。'); } if (options.yunliMode === 'history' && !options.duration && options.beginTime && options.endTime) { var beginTime = new Date(options.beginTime).getTime(); var endTime = new Date(options.endTime).getTime(); console.log('beginTime', beginTime, endTime); if (isNaN(beginTime) || isNaN(endTime)) { throw new Error('beginTime或者endTime格式错误'); } else { options.duration = Math.floor((endTime - beginTime) / 1000); if (isNaN(options.duration) || options.duration < 0) { throw new Error('beginTime或者endTime格式错误'); } } } this.options_ = options || {}; this.el_ = el; this.readyCallback_ = readyCallback; //重试次数 this.retryTime = 0; //最多重试次数 this.maxRetryTime = options.maxRetryTime || 3; //是否自动重试 this.autoRetry = options.autoRety !== undefined ? options.autoRetry : true; //加载中重试前等待时间 this.waitingInterval = options.waitingInterval || 5000; this.waitingTimer = null; this._keepAliveTimer = null; this._keepAliveInterval = options.keepAliveInterval || 15000; //心跳保活默认开启 this.keepAlive = options.keepAlive || true; //是否播放状态 this.isPlaying = false; //处理源的格式 if (this.options_.sources) { this.options_.sources = this._parseSource(this.options_.sources); } this.setEnv(); this.setOptions(options); //实例化videojs播放器 this.initPlayer(readyCallback); return this.player_; }; YunliVjsPlayer.prototype.setEnv = function () { var _this = this; // 添加语言 this.addLang(); this._addSnapButton(); //添加录制功能 if (this.options_.record) { this._addRecordButton(); } var onLineHandler = function onLineHandler(e) { console.log(e, "you're online"); if (_this.player_) { _this.player_.error(null); _this.src(_this.options_.sources); _this.player_.play(); } }; var offLineHandler = function offLineHandler(e) { console.log(e, "you're offline"); if (_this.player_) { _this.errorHandler('offline'); } }; window.addEventListener('online', onLineHandler); window.addEventListener('offline', offLineHandler); if (!navigator.onLine) { offLineHandler(null); } }; YunliVjsPlayer.prototype.addLang = function () { // 添加语言 videojs.addLanguage('zh-CN', lang); }; YunliVjsPlayer.prototype.setOptions = function () { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var controlBarList = ['playToggle', 'currentTimeDisplay', 'timeDivider', 'durationDisplay', 'progressControl', 'liveDisplay', 'seekToLive', 'customControlSpacer', 'recordButton', 'snapButton', 'playbackRateMenuButton', 'chaptersButton', 'descriptionsButton', 'volumePanel', 'subsCapsButton', 'audioTrackButton', 'fullscreenToggle']; // 是否支持画中画模式 if ('exitPictureInPicture' in document) { splice$2(controlBarList).call(controlBarList, controlBarList.length - 1, 0, 'pictureInPictureToggle'); } var options = { language: 'zh-CN', controls: true, autoplay: false, techOrder: ['html5', 'flvjs', 'flash'], record: false, snap: { autoSave: true }, controlBar: { children: controlBarList, volumePanel: { inline: false, vertical: true } }, flash: { swf: './lib/video-js.swf' } }; //直播 if (opt.yunliMode === 'live') { splice$2(controlBarList).call(controlBarList, 4, 1); options.controlBar.timeDivider = false; options.controlBar.durationDisplay = false; } else { options.playbackRates = ['0.25', '0.5', '1', '2', '4', '8', '16']; } options = videojs.mergeOptions(options, opt); this.options_ = options; return options; }; YunliVjsPlayer.prototype.initPlayer = function () { var this_ = this; this.player_ = videojs(this.el_, this.options_, function (p) { this_.replaceEvents(); this_.replaceSpinner(); console.log('ccccccfill', this_.options_, this_.player_); var options_ = this_.options_; var player_ = this_.player_; if (options_.fillScreen && player_ && player_.el_) { console.log('ccccccfill'); player_.el_.querySelector('video').style.objectFit = 'fill'; } // 添加宽高 if (options_.height) { player_.el_.style.height = options_.height; } if (options_.width) { player_.el_.style.width = options_.width; } if (this_.options_.yunliMode === 'history' && this_.options_.duration) { this_.replaceControlBarEvent(); } // player reader callback if (this_.readyCallback_ && typeof this_.readyCallback_ === 'function') { this_.readyCallback_(p); } if ((this_.options_.yunliMode === 'live' || this_.options_.yunliMode === 'history') && this_.keepAlive) { this_._keepAlive(); } }); this.player_.on('error', function (err) { var _context; var error = this_.player_.error(); console.log('on error', error); setTimeout$1(function () { var _this_$player_, _this_$player_$el_, _this_$player_$el_$cl; (_this_$player_ = this_.player_) === null || _this_$player_ === void 0 ? void 0 : (_this_$player_$el_ = _this_$player_.el_) === null || _this_$player_$el_ === void 0 ? void 0 : (_this_$player_$el_$cl = _this_$player_$el_.classList) === null || _this_$player_$el_$cl === void 0 ? void 0 : _this_$player_$el_$cl.remove('vjs-loading-data'); }, 100); if (error && indexOf$2(_context = ['timeout', 'offline', 'notfound', 'shutdown', 'neterror']).call(_context, error.message) > -1) { //if(this_.onError && typeof this_.onError === 'function'){ this_.onError.call(this_, error); //} return; } if (!navigator.onLine) { this_.errorHandler('offline'); return; } if (error && error.code === 4) { this_.errorHandler('notfound'); } else if (error && error.code) { this_.errorHandler('shutdown'); } }); return this.player_; }; } var hiddenKeys = {}; var indexOf$3 = arrayIncludes.indexOf; var objectKeysInternal = function (object, names) { var O = toIndexedObject(object); var i = 0; var result = []; var key; for (key in O) !has(hiddenKeys, key) && has(O, key) && result.push(key); // Don't enum bug & hidden keys while (names.length > i) if (has(O, key = names[i++])) { ~indexOf$3(result, key) || result.push(key); } return result; }; // IE8- don't enum bug keys var enumBugKeys = [ 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf' ]; // `Object.keys` method // https://tc39.es/ecma262/#sec-object.keys // eslint-disable-next-line es/no-object-keys -- safe var objectKeys = Object.keys || function keys(O) { return objectKeysInternal(O, enumBugKeys); }; // eslint-disable-next-line es/no-object-getownpropertysymbols -- safe var f$3 = Object.getOwnPropertySymbols; var objectGetOwnPropertySymbols = { f: f$3 }; // eslint-disable-next-line es/no-object-assign -- safe var $assign = Object.assign; // eslint-disable-next-line es/no-object-defineproperty -- required for testing var defineProperty = Object.defineProperty; // `Object.assign` method // https://tc39.es/ecma262/#sec-object.assign var objectAssign = !$assign || fails(function () { // should have correct order of operations (Edge bug) if (descriptors && $assign({ b: 1 }, $assign(defineProperty({}, 'a', { enumerable: true, get: function () { defineProperty(this, 'b', { value: 3, enumerable: false }); } }), { b: 2 })).b !== 1) return true; // should work with symbols and should have deterministic property order (V8 bug) var A = {}; var B = {}; // eslint-disable-next-line es/no-symbol -- safe var symbol = Symbol(); var alphabet = 'abcdefghijklmnopqrst'; A[symbol] = 7; alphabet.split('').forEach(function (chr) { B[chr] = chr; }); return $assign({}, A)[symbol] != 7 || objectKeys($assign({}, B)).join('') != alphabet; }) ? function assign(target, source) { // eslint-disable-line no-unused-vars -- required for `.length` var T = toObject(target); var argumentsLength = arguments.length; var index = 1; var getOwnPropertySymbols = objectGetOwnPropertySymbols.f; var propertyIsEnumerable = objectPropertyIsEnumerable.f; while (argumentsLength > index) { var S = indexedObject(arguments[index++]); var keys = getOwnPropertySymbols ? objectKeys(S).concat(getOwnPropertySymbols(S)) : objectKeys(S); var length = keys.length; var j = 0; var key; while (length > j) { key = keys[j++]; if (!descriptors || propertyIsEnumerable.call(S, key)) T[key] = S[key]; } } return T; } : $assign; // `Object.assign` method // https://tc39.es/ecma262/#sec-object.assign // eslint-disable-next-line es/no-object-assign -- required for testing _export({ target: 'Object', stat: true, forced: Object.assign !== objectAssign }, { assign: objectAssign }); var assign = path.Object.assign; var assign$1 = assign; var assign$2 = assign$1; var IS_CONCAT_SPREADABLE = wellKnownSymbol('isConcatSpreadable'); var MAX_SAFE_INTEGER$1 = 0x1FFFFFFFFFFFFF; var MAXIMUM_ALLOWED_INDEX_EXCEEDED = 'Maximum allowed index exceeded'; // We can't use this feature detection in V8 since it causes // deoptimization and serious performance degradation // https://github.com/zloirock/core-js/issues/679 var IS_CONCAT_SPREADABLE_SUPPORT = engineV8Version >= 51 || !fails(function () { var array = []; array[IS_CONCAT_SPREADABLE] = false; return array.concat()[0] !== array; }); var SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('concat'); var isConcatSpreadable = function (O) { if (!isObject(O)) return false; var spreadable = O[IS_CONCAT_SPREADABLE]; return spreadable !== undefined ? !!spreadable : isArray(O); }; var FORCED = !IS_CONCAT_SPREADABLE_SUPPORT || !SPECIES_SUPPORT; // `Array.prototype.concat` method // https://tc39.es/ecma262/#sec-array.prototype.concat // with adding support of @@isConcatSpreadable and @@species _export({ target: 'Array', proto: true, forced: FORCED }, { // eslint-disable-next-line no-unused-vars -- required for `.length` concat: function concat(arg) { var O = toObject(this); var A = arraySpeciesCreate(O, 0); var n = 0; var i, k, length, len, E; for (i = -1, length = arguments.length; i < length; i++) { E = i === -1 ? O : arguments[i]; if (isConcatSpreadable(E)) { len = toLength(E.length); if (n + len > MAX_SAFE_INTEGER$1) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED); for (k = 0; k < len; k++, n++) if (k in E) createProperty(A, n, E[k]); } else { if (n >= MAX_SAFE_INTEGER$1) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED); createProperty(A, n++, E); } } A.length = n; return A; } }); var concat = entryVirtual('Array').concat; var ArrayPrototype$2 = Array.prototype; var concat_1 = function (it) { var own = it.concat; return it === ArrayPrototype$2 || (it instanceof Array && own === ArrayPrototype$2.concat) ? concat : own; }; var concat$1 = concat_1; var concat$2 = concat$1; /** * Returns whether an object is `Promise`-like (i.e. has a `then` method). * * @param {Object} value * An object that may or may not be `Promise`-like. * * @return {boolean} * Whether or not the object is `Promise`-like. */ function isPromise(value) { return value !== undefined && value !== null && typeof value.then === 'function'; } /** * Silence a Promise-like object. * * This is useful for avoiding non-harmful, but potentially confusing "uncaught * play promise" rejection error messages. * * @param {Object} value * An object that may or may not be `Promise`-like. */ function silencePromise(value) { if (isPromise(value)) { value.then(null, function (e) {}); } } /** * @file format-time.js * @module format-time */ /** * Format seconds as a time string, H:MM:SS or M:SS. Supplying a guide (in * seconds) will force a number of leading zeros to cover the length of the * guide. * * @private * @param {number} seconds * Number of seconds to be turned into a string * * @param {number} guide * Number (in seconds) to model the string after * * @return {string} * Time formatted as H:MM:SS or M:SS */ var defaultImplementation = function defaultImplementation(seconds, guide) { seconds = seconds < 0 ? 0 : seconds; var s = Math.floor(seconds % 60); var m = Math.floor(seconds / 60 % 60); var h = Math.floor(seconds / 3600); var gm = Math.floor(guide / 60 % 60); var gh = Math.floor(guide / 3600); // handle invalid times if (isNaN(seconds) || seconds === Infinity) { // '-' is false for all relational operators (e.g. <, >=) so this setting // will add the minimum number of fields specified by the guide h = m = s = '-'; } // Check if we need to show hours h = h > 0 || gh > 0 ? h + ':' : ''; // If hours are showing, we may need to add a leading zero. // Always show at least one digit of minutes. m = ((h || gm >= 10) && m < 10 ? '0' + m : m) + ':'; // Check if leading zero is need for seconds s = s < 10 ? '0' + s : s; return h + m + s; }; // Internal pointer to the current implementation. var implementation = defaultImplementation; /** * Delegates to either the default time formatting function or a custom * function supplied via `setFormatTime`. * * Formats seconds as a time string (H:MM:SS or M:SS). Supplying a * guide (in seconds) will force a number of leading zeros to cover the * length of the guide. * * @static * @example formatTime(125, 600) === "02:05" * @param {number} seconds * Number of seconds to be turned into a string * * @param {number} guide * Number (in seconds) to model the string after * * @return {string} * Time formatted as H:MM:SS or M:SS */ function formatTime(seconds) { var guide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : seconds; return implementation(seconds, guide); } function eventsMixin(YunliVjsPlayer) { YunliVjsPlayer.prototype.errorHandler = function (type) { var player = this.player_; window.clearTimeout(this.waitingTimer); if (type !== 'timeout' && this.autoRetry) { this._handleWaiting.call(this); } silencePromise(player.pause()); var typeTips = { timeout: '连接超时', offline: '无网络', shutdown: '视频中断', notfound: '视频未找到', neterror: '网络错误' }; if (this.options_.errorTexts) { typeTips = assign$2({}, typeTips, this.options_.errorTexts); } var vjsModalContent = this.player_.el_.querySelector('.vjs-modal-dialog-content'); player.error(type); if (vjsModalContent) { if (this.retryTime < this.maxRetryTime) { vjsModalContent.innerHTML = "\n <div class=\"vjs-loading-spinner\" dir=\"ltr\">\n <i class=\"yl-spin-dot-item\"></i>\n <i class=\"yl-spin-dot-item\"></i>\n <i class=\"yl-spin-dot-item\"></i>\n <i class=\"yl-spin-dot-item\"></i>\n </div>"; } else { var _context; vjsModalContent.innerHTML = concat$2(_context = "\n <div class=\"vjs-yunli-error\">\n <div class=\"vjs-yunli-".concat(type, "\"></div>\n <div class=\"vjs-yunli-tip\">")).call(_context, typeTips[type], "</div>\n </div>\n "); } } }; // 替换loading图标 YunliVjsPlayer.prototype.replaceSpinner = function () { var el = (this.player_.el_ || document).querySelector('.vjs-loading-spinner'); el.innerHTML = ''; for (var i = 0; i < 4; i++) { var it = document.createElement('i'); it.classList.add('yl-spin-dot-item'); el.appendChild(it); } }; YunliVjsPlayer.prototype._handleWaiting = function () { var _this = this; if (this.options_.eventMode === 'monitor') { return; } console.log('retry', this.retryTime, this.player_.id_, this.waitingTimer, this); if (this.waitingTimer) { window.clearTimeout(this.waitingTimer); } if (this.retryTime < this.maxRetryTime) { //silencePromise(this.player_.play()) this.waitingTimer = setTimeout$1(function () { if (!_this.player_.paused() && _this.isPlaying) { return; } console.log('retry in timeout', _this.player_.id_, _this.waitingTimer); //let sources = this.player_.currentSources() //sources = sources.length === 0 ? this.player_.options_.sources : sources if (_this.player_.techName_ === 'Flash') { _this.player_.reset(); } if (_this.player_.techName_ !== 'Flash') { _this.src(_this.options_.sources); } if (_this.player_.techName_ === 'Flash') { _this.player_.play(); } /* try{ if (this.options_.sources[0].src !== this.player_.currentSources()[0].src) { console.log('retry in timeout',this.options_.sources, this.player_.currentSources()) this.src(this.options_.sources) } else { this.player_.play() } } catch(err){ console.log('err', err) } */ //this.player_.play() _this._handleWaiting.call(_this); _this.retryTime += 1; }, this.waitingInterval); } else { //超时 this.errorHandler('timeout'); } }; YunliVjsPlayer.prototype.replaceEvents = function () { var _this3 = this; console.log('bindEvent'); var _this$options_ = this.options_, duration = _this$options_.duration, eventMode = _this$options_.eventMode, yunliMode = _this$options_.yunliMode; var player_ = this.player_; var this_ = this; if (eventMode === 'monitor') { return; } //回放模式 if (yunliMode === 'history' && duration) { //当前播放时间 var _currentTime = function _currentTime(seconds) { //console.log('currentTIme', seconds, this) if (typeof seconds !== 'undefined') { console.log('currentTIme ii', seconds, this); if (seconds < 0) { seconds = 0; } if (!this.isReady_ || this.changingSrc_ || !this.tech_ || !this.tech_.isReady_) { this.cache_.initTime = seconds; this.off('canplay', this.applyInitTime_); this.one('canplay', this.applyInitTime_); return; } this.techCall_('setCurrentTime', seconds); this.cache_.initTime = seconds; this.cache_.currentTime = seconds; this_.ylJumpTime = seconds; return; } // cache last currentTime and return. default to 0 seconds // // Caching the currentTime is meant to prevent a massive amount of reads on the tech's // currentTime when scrubbing, but may not provide much performance benefit afterall. // Should be tested. Also something has to read the actual current time or the cache will // never get updated. this.cache_.currentTime = this.techGet_('currentTime') || 0; return this.cache_.currentTime; }; //设置进度条 player_.duration = function () { return duration; }; player_.currentTime = _currentTime; player_.tech_.setCurrentTime = function (time) { console.log('tech set currentTime', time, this); //this.lastSeekTarget_ = time if (this.el_.vjs_setProperty) { this.el_.vjs_setProperty('currentTime', time); } }; player_.controlBar.currentTimeDisplay.updateTextNode_ = function () { var _this2 = this; var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; if (this_.isJumping) { time = this_.ylJumpTime || 0; } else { time = time + (this_.ylJumpTime || 0); } time = formatTime(time); if (this.formattedTime_ === time) { return; } this.formattedTime_ = time; this.requestAnimationFrame(function () { if (!_this2.contentEl_) { return; } var oldNode = _this2.textNode_; _this2.textNode_ = document.createTextNode(_this2.formattedTime_); if (!_this2.textNode_) { return; } if (oldNode) { _this2.contentEl_.replaceChild(_this2.textNode_, oldNode); } else { _this2.contentEl_.appendChild(_this2.textNode_); } }); }; player_.on('play', function () { this_.isJumping = false; //clearTimeout(this_.waitingTimer) console.log('play', player_.id_, this_.options_.sources); if (this_.waitingTimer) { window.clearTimeout(this_.waitingTimer); } setTimeout$1(function () { player_.el_.classList.remove('vjs-loading-data