ezuikit.js 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080
  1. /**
  2. * jssdk 3.0
  3. */
  4. (function (global, factory) {
  5. "use strict";
  6. if (typeof module === "object" && typeof module.exports === "object") {
  7. module.exports = global.document ?
  8. factory(global, true) :
  9. function (w) {
  10. if (!w.document) {
  11. throw new Error("EZUIPlayer requires a window with a document");
  12. }
  13. return factory(w);
  14. };
  15. } else {
  16. factory(global);
  17. }
  18. // Pass this if window is not defined yet
  19. })(typeof window !== "undefined" ? window : this, function (window, noGlobal) {
  20. /**
  21. * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
  22. */
  23. !function (a, b) { function c(a, b) { var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML = "x<style>" + b + "</style>", d.insertBefore(c.lastChild, d.firstChild) } function d() { var a = t.elements; return "string" == typeof a ? a.split(" ") : a } function e(a, b) { var c = t.elements; "string" != typeof c && (c = c.join(" ")), "string" != typeof a && (a = a.join(" ")), t.elements = c + " " + a, j(b) } function f(a) { var b = s[a[q]]; return b || (b = {}, r++, a[q] = r, s[r] = b), b } function g(a, c, d) { if (c || (c = b), l) return c.createElement(a); d || (d = f(c)); var e; return e = d.cache[a] ? d.cache[a].cloneNode() : p.test(a) ? (d.cache[a] = d.createElem(a)).cloneNode() : d.createElem(a), !e.canHaveChildren || o.test(a) || e.tagUrn ? e : d.frag.appendChild(e) } function h(a, c) { if (a || (a = b), l) return a.createDocumentFragment(); c = c || f(a); for (var e = c.frag.cloneNode(), g = 0, h = d(), i = h.length; i > g; g++)e.createElement(h[g]); return e } function i(a, b) { b.cache || (b.cache = {}, b.createElem = a.createElement, b.createFrag = a.createDocumentFragment, b.frag = b.createFrag()), a.createElement = function (c) { return t.shivMethods ? g(c, a, b) : b.createElem(c) }, a.createDocumentFragment = Function("h,f", "return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&(" + d().join().replace(/[\w\-:]+/g, function (a) { return b.createElem(a), b.frag.createElement(a), 'c("' + a + '")' }) + ");return n}")(t, b.frag) } function j(a) { a || (a = b); var d = f(a); return !t.shivCSS || k || d.hasCSS || (d.hasCSS = !!c(a, "article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")), l || i(a, d), a } var k, l, m = "3.7.3", n = a.html5 || {}, o = /^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i, p = /^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i, q = "_html5shiv", r = 0, s = {}; !function () { try { var a = b.createElement("a"); a.innerHTML = "<xyz></xyz>", k = "hidden" in a, l = 1 == a.childNodes.length || function () { b.createElement("a"); var a = b.createDocumentFragment(); return "undefined" == typeof a.cloneNode || "undefined" == typeof a.createDocumentFragment || "undefined" == typeof a.createElement }() } catch (c) { k = !0, l = !0 } }(); var t = { elements: n.elements || "abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video", version: m, shivCSS: n.shivCSS !== !1, supportsUnknownElements: l, shivMethods: n.shivMethods !== !1, type: "default", shivDocument: j, createElement: g, createDocumentFragment: h, addElements: e }; a.html5 = t, j(b), "object" == typeof module && module.exports && (module.exports = t) }("undefined" != typeof window ? window : this, document);
  24. /*! @source http://purl.eligrey.com/github/classList.js/blob/master/classList.js */
  25. if ("document" in self) { if (!("classList" in document.createElement("_"))) { (function (j) { "use strict"; if (!("Element" in j)) { return } var a = "classList", f = "prototype", m = j.Element[f], b = Object, k = String[f].trim || function () { return this.replace(/^\s+|\s+$/g, "") }, c = Array[f].indexOf || function (q) { var p = 0, o = this.length; for (; p < o; p++) { if (p in this && this[p] === q) { return p } } return -1 }, n = function (o, p) { this.name = o; this.code = DOMException[o]; this.message = p }, g = function (p, o) { if (o === "") { throw new n("SYNTAX_ERR", "An invalid or illegal string was specified") } if (/\s/.test(o)) { throw new n("INVALID_CHARACTER_ERR", "String contains an invalid character") } return c.call(p, o) }, d = function (s) { var r = k.call(s.getAttribute("class") || ""), q = r ? r.split(/\s+/) : [], p = 0, o = q.length; for (; p < o; p++) { this.push(q[p]) } this._updateClassName = function () { s.setAttribute("class", this.toString()) } }, e = d[f] = [], i = function () { return new d(this) }; n[f] = Error[f]; e.item = function (o) { return this[o] || null }; e.contains = function (o) { o += ""; return g(this, o) !== -1 }; e.add = function () { var s = arguments, r = 0, p = s.length, q, o = false; do { q = s[r] + ""; if (g(this, q) === -1) { this.push(q); o = true } } while (++r < p); if (o) { this._updateClassName() } }; e.remove = function () { var t = arguments, s = 0, p = t.length, r, o = false, q; do { r = t[s] + ""; q = g(this, r); while (q !== -1) { this.splice(q, 1); o = true; q = g(this, r) } } while (++s < p); if (o) { this._updateClassName() } }; e.toggle = function (p, q) { p += ""; var o = this.contains(p), r = o ? q !== true && "remove" : q !== false && "add"; if (r) { this[r](p) } if (q === true || q === false) { return q } else { return !o } }; e.toString = function () { return this.join(" ") }; if (b.defineProperty) { var l = { get: i, enumerable: true, configurable: true }; try { b.defineProperty(m, a, l) } catch (h) { if (h.number === -2146823252) { l.enumerable = false; b.defineProperty(m, a, l) } } } else { if (b[f].__defineGetter__) { m.__defineGetter__(a, i) } } }(self)) } else { (function () { var b = document.createElement("_"); b.classList.add("c1", "c2"); if (!b.classList.contains("c2")) { var c = function (e) { var d = DOMTokenList.prototype[e]; DOMTokenList.prototype[e] = function (h) { var g, f = arguments.length; for (g = 0; g < f; g++) { h = arguments[g]; d.call(this, h) } } }; c("add"); c("remove") } b.classList.toggle("c3", false); if (b.classList.contains("c3")) { var a = DOMTokenList.prototype.toggle; DOMTokenList.prototype.toggle = function (d, e) { if (1 in arguments && !this.contains(d) === !e) { return e } else { return a.call(this, d) } } } b = null }()) } };
  26. Date.prototype.Format = function (fmt) { //author: meizz
  27. var o = {
  28. "M+": this.getMonth() + 1, //月份
  29. "d+": this.getDate(), //日
  30. "h+": this.getHours(), //小时
  31. "m+": this.getMinutes(), //分
  32. "s+": this.getSeconds(), //秒
  33. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  34. "S": this.getMilliseconds() //毫秒
  35. };
  36. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  37. for (var k in o)
  38. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  39. return fmt;
  40. };
  41. var Domain = 'https://open.ys7.com';
  42. var logDomain = 'https://log.ys7.com/statistics.do';
  43. var jqueryJS = Domain + '/sdk/js/2.0/js/jquery.min.js';
  44. var ckplayerJS = Domain + '/sdk/js/2.0/js/ckplayer/ckplayer.js';
  45. var ckplayerSWF = Domain + '/sdk/js/2.0/js/ckplayer/ckplayer.swf';
  46. var m3u8SWF = Domain + '/sdk/js/2.0/js/ckplayer/m3u8.swf';
  47. var flv_js = Domain + '/sdk/js/2.0/js/flv.min.js';
  48. var hlsJS = Domain + '/sdk/js/2.0/js/hls.min.js';
  49. var mpegJS = Domain + '/sdk/js/2.0/js/jsmpeg.min.js';
  50. var wav = Domain + '/sdk/js/2.0/js/wav-audio-encoder.js';
  51. // 当前页面是否是https协议
  52. var isHttps = window.location.protocol === 'https:' ? true : false;
  53. // 是否为移动端
  54. var isMobile = !!navigator.userAgent.match(/(iPhone|iPod|iPad|Android|ios|SymbianOS)/i);
  55. var testVideo = document.createElement('video');
  56. // 是否支持video标签和addEventListener方法(主要为了区别ie8)
  57. var isModernBrowser = !!testVideo.canPlayType && !!window.addEventListener;
  58. // 是否能使用video原生播放hls,目前只有safari可以支持原生video播放。
  59. var isNativeSupportHls = isModernBrowser && testVideo.canPlayType('application/vnd.apple.mpegURL');
  60. // 是否能使用hls.js播放
  61. var isSupportHls = false;
  62. // 是否使用flash
  63. var useFlash = false;
  64. // 初始化播放时间
  65. var playStartTime = new Date().getTime();
  66. // 本地信息上报
  67. var LOCALINFO = 'open_netstream_localinfo';
  68. // 预览主表上报
  69. var PLAY_MAIN = 'open_netstream_play_main';
  70. // 日志上报(轻应用独立上报)
  71. var LOCALINFO_EZUIKIT = 'open_ezuikit_localinfo';
  72. var PERFORMANCE_EZUIKIT = 'open_ezuikit_performance';
  73. var appKey = "";
  74. function dclog(obj) {
  75. var domain = window.location.protocol + '//' + window.location.host;
  76. var logObj = {
  77. Ver: 'v.2.6.5',
  78. PlatAddr: domain,
  79. ExterVer: 'Ez.2.6.5',
  80. OpId: uuid(),
  81. CltType: 102,
  82. AppId: appKey,
  83. StartTime: (new Date()).Format('yyyy-MM-dd hh:mm:ss.S'), // 每个日志包含当前的时间
  84. OS: navigator.platform
  85. }
  86. for (var i in obj) {
  87. logObj[i] = obj[i];
  88. }
  89. var tempArray = [];
  90. for (var j in logObj) {
  91. tempArray.push(j + '=' + logObj[j]);
  92. }
  93. var params = '?' + tempArray.join('&');
  94. // 上报一次本地统计信息
  95. var img = new Image();
  96. img.src = logDomain + params;
  97. }
  98. // 日志上报-2019-09-10
  99. function ezuikitDclog(obj) {
  100. var domain = window.location.protocol + '//' + window.location.host;
  101. var logObj = {
  102. version: 'v.2.6.5',
  103. plate_addr: domain,
  104. appId: appKey,
  105. st: new Date().getTime(), // 每个日志包含当前的时间
  106. }
  107. for (var i in obj) {
  108. logObj[i] = obj[i];
  109. }
  110. var tempArray = [];
  111. for (var j in logObj) {
  112. tempArray.push(j + '=' + logObj[j]);
  113. }
  114. var params = '?' + tempArray.join('&');
  115. // 上报一次本地统计信息
  116. var img = new Image();
  117. img.src = logDomain + params;
  118. }
  119. var RTMP_REG = /^rtmp/;
  120. var HLS_REG = /\.m3u8/;
  121. // 获取元素样式
  122. function getStyle(el) {
  123. return window.getComputedStyle
  124. ? window.getComputedStyle(el, null)
  125. : el.currentStyle;
  126. }
  127. // 加载js
  128. function addJs(filepath, callback) {
  129. var oJs = document.createElement("script");
  130. oJs.setAttribute("src", filepath);
  131. oJs.onload = callback;
  132. document.getElementsByTagName("head")[0].appendChild(oJs);
  133. }
  134. // 通用请求方法
  135. function request(url, method, params, header, success, error) {
  136. var _url = url;
  137. var http_request = new XMLHttpRequest();
  138. http_request.onreadystatechange = function () {
  139. if (http_request.readyState == 4) {
  140. if (http_request.status == 200) {
  141. if (isJSON(http_request.responseText)) {
  142. var _data = JSON.parse(http_request.responseText);
  143. success(_data);
  144. } else {
  145. success(http_request.responseText)
  146. }
  147. }
  148. }
  149. };
  150. http_request.open(method, _url, true);
  151. // http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  152. var data = new FormData();
  153. for (var i in params) {
  154. data.append(i, params[i]);
  155. }
  156. http_request.send(data);
  157. };
  158. /** 获取url参数 */
  159. function getQueryString(name, url) { var r = new RegExp("(\\?|#|&)" + name + "=(.*?)(#|&|$)"); var m = (url || location.href).match(r); return decodeURIComponent(m ? m[2] : ''); }
  160. /** 判断是否为promise对象 */
  161. function isPromise(obj) { return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; }
  162. /** 生成uuid */
  163. function uuid() { var s = []; var hexDigits = "0123456789abcdef"; for (var i = 0; i < 36; i++) { s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1) }; s[14] = "4"; s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); s[8] = s[13] = s[18] = s[23] = "-"; var uuid = s.join(""); return uuid; }
  164. /**获取浏览器名称,版本 */
  165. function getBrowserInfo() { var Sys = {}; var ua = navigator.userAgent.toLowerCase(); var re = /(msie|firefox|chrome|opera|version).*?([\d.]+)/; var m = ua.match(re); try { Sys.browser = m[1].replace(/version/, "'safari"); Sys.ver = m[2]; } catch (e) { console.log("getBrowserInfo fail.") } return Sys; }
  166. /** 是否为JSON格式字符串 */
  167. function isJSON(str) { if (typeof str == 'string') { try { var obj = JSON.parse(str); if (typeof obj == 'object' && obj) { return true; } else { return false; } } catch (e) { return false; } } console.log('It is not a string!') }
  168. /** insertAfter */
  169. function insertAfter(newElement, targetElement) { var parent = targetElement.parentNode; if (parent.lastChild == targetElement) { parent.appendChild(newElement); } else { parent.insertBefore(newElement, targetElement.nextSibling); } }
  170. var EZUIPlayer = function (playParams) {
  171. if (!isModernBrowser) {
  172. throw new Error('不支持ie8等低版本浏览器');
  173. return;
  174. }
  175. /**定义播放配置项 */
  176. this.opt = {};
  177. this.opt.sources = [];
  178. this.handlers = {};
  179. // 修订 - 支持JS Decoder 允许非字符串配置项
  180. if (typeof playParams === 'object' && playParams.hasOwnProperty('decoderPath')) {
  181. if (typeof playParams.audioId === 'undefined') {
  182. playParams["audioId"] = 0;
  183. }
  184. this.playParams = playParams;
  185. /* 校验播放器配置参数合法性 */
  186. var oS = document.createElement('style');
  187. document.getElementsByTagName("head")[0].appendChild(oS);
  188. oS.innerHTML = '.draw-window {border: none!important}';
  189. // 解码器路径
  190. if (typeof playParams.decoderPath !== 'string' || typeof playParams.decoderPath === 'undefined') {
  191. throw new Error('EZUIDecoder requires the path of decoder');
  192. return;
  193. }
  194. // Id
  195. if (typeof playParams.id !== 'string' || typeof playParams.id === 'undefined') {
  196. throw new Error('EZUIDecoder requires parameter id');
  197. return;
  198. }
  199. if (typeof playParams.url !== 'string' || typeof playParams.url === 'undefined') {
  200. throw new Error('EZUIDecoder requires parameter url');
  201. return;
  202. }
  203. // 状态提示
  204. this.loadingStart = function () {
  205. var oS = document.createElement('style');
  206. document.getElementsByTagName("head")[0].appendChild(oS);
  207. oS.innerHTML = '@keyframes antRotate {to {transform: rotate(400deg);transform-origin:50% 50%;}} .loading {display: inline-block;z-index: 1000;-webkit-animation: antRotate 1s infinite linear;animation: antRotate 1s infinite linear;}';
  208. if (playParams && playParams.id) {
  209. var domId = playParams.id;
  210. var domElement = document.getElementById(domId);
  211. var windowWidth = domElement.offsetWidth;
  212. var windowHeight = domElement.offsetHeight || playParams.height || 400;
  213. var offsetTop = domElement.offsetTop;
  214. var offsetLeft = domElement.offsetLeft;
  215. // 先执行清空loading
  216. if (document.getElementById('loading-id-0')) {
  217. document.getElementById('loading-id-0').parentNode.removeChild(document.getElementById('loading-id-0'))
  218. }
  219. var loadingContainerDOM = document.createElement('div');
  220. loadingContainerDOM.setAttribute('id', 'loading-id-0');
  221. var style = 'position:absolute;outline:none;'
  222. style += 'width: 0px;'
  223. style += 'height: 0px;'
  224. style += 'top:' + offsetTop + 'px;'
  225. style += 'left:' + offsetLeft + 'px;'
  226. loadingContainerDOM.setAttribute('style', style);
  227. var loadingContainer = document.getElementById("loading-id-0");
  228. loadingContainerDOM.style.height = windowHeight;
  229. loadingContainerDOM.setAttribute('class', 'loading-container');
  230. // loadingContainerDOM.innerHTML= loading;
  231. insertAfter(loadingContainerDOM, domElement);
  232. var splitBasis = playParams.splitBasis || 1;
  233. var windowLength = playParams.url.split(",").length;
  234. for (var i = 0; i < windowLength; i++) {
  235. var loadingContainer = document.createElement('div');
  236. var loadingStatusDOM = document.createElement('div');
  237. loadingContainer.setAttribute('class', 'loading-item');
  238. loadingContainer.setAttribute('id', 'loading-item-' + i);
  239. //loadingContainer.setAttribute('style','display:inline-flex;flex-direction:column;justify-content:center;align-items: center;width:'+(windowWidth / splitBasis)+'px;height:'+(windowHeight /splitBasis )+'px;outline:none;vertical-align: top;position:absolute');
  240. var style = 'display:inline-flex;flex-direction:column;justify-content:center;align-items: center;width:' + (windowWidth / splitBasis) + 'px;height:' + (windowHeight / splitBasis) + 'px;outline:none;vertical-align: top;position:absolute;';
  241. style += ('left:' + calLoadingPostion(windowHeight, windowWidth, splitBasis, i).left + 'px;');
  242. style += ('top:' + calLoadingPostion(windowHeight, windowWidth, splitBasis, i).top + 'px;');
  243. loadingContainer.setAttribute('style', style);
  244. function calLoadingPostion(windowHeight, windowWidth, splitBasis, i) {
  245. var top = parseInt(i / splitBasis, 10) * (windowHeight / splitBasis);
  246. var left = (i % splitBasis) * (windowWidth / splitBasis);
  247. return {
  248. top: top,
  249. left: left
  250. }
  251. }
  252. var loadingDOM = document.createElement('div');
  253. loadingStatusDOM.innerHTML = "";
  254. loadingStatusDOM.style.color = "#fff";
  255. loadingDOM.setAttribute('class', 'loading');
  256. var loading = '<svg t="1567069979438" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2399" width="32" height="32"><path d="M538.5344 266.4448a133.12 133.12 0 1 1 133.12-133.12 133.4272 133.4272 0 0 1-133.12 133.12zM255.0144 372.1984a121.6768 121.6768 0 1 1 121.6768-121.6768 121.856 121.856 0 0 1-121.6768 121.6768zM134.72 647.424a107.3664 107.3664 0 1 1 107.3664-107.264A107.52 107.52 0 0 1 134.72 647.424z m120.32 272.4608a90.9824 90.9824 0 1 1 90.9824-90.9824A91.1616 91.1616 0 0 1 255.04 919.8848zM538.5344 1024a79.36 79.36 0 1 1 79.36-79.36 79.36 79.36 0 0 1-79.36 79.36z m287.6928-134.144a64.1792 64.1792 0 1 1 64.1792-64.1792 64.3584 64.3584 0 0 1-64.1792 64.1792z m117.76-296.704a52.6336 52.6336 0 1 1 52.6592-52.6336 52.608 52.608 0 0 1-52.6336 52.6336z m-158.72-338.7136a40.96 40.96 0 1 1 12.0064 28.8512 40.5248 40.5248 0 0 1-12.0064-28.8512z" fill="#ffffff" p-id="2400"></path></svg>';
  257. if (playParams.loading && playParams.loading.svg) {
  258. loading = playParams.loading.svg;
  259. }
  260. loadingDOM.innerHTML = loading;
  261. loadingContainer.appendChild(loadingDOM);
  262. // loadingContainer.appendChild(loading);
  263. loadingContainer.appendChild(loadingStatusDOM);
  264. loadingContainerDOM.appendChild(loadingContainer)
  265. }
  266. }
  267. }
  268. this.loadingSet = function (index, opt) {
  269. var loadingContainer = document.getElementById('loading-id-0');
  270. if (document.getElementById('loading-item-' + index)) {
  271. var textElement = document.getElementById('loading-item-' + index).childNodes[1];
  272. textElement.innerHTML = opt.text;
  273. if (opt.color) {
  274. textElement.style.color = opt.color;
  275. }
  276. }
  277. }
  278. this.loadingSetIcon = function (i, type) {
  279. var _this = this;
  280. if (playParams && playParams.id) {
  281. var domId = playParams.id;
  282. var domElement = document.getElementById(domId);
  283. var windowWidth = domElement.offsetWidth;
  284. var windowHeight = domElement.offsetHeight || playParams.height || 400;
  285. var offsetTop = domElement.offsetTop;
  286. var offsetLeft = domElement.offsetLeft;
  287. // 先执行清空loading
  288. if (document.getElementById('loading-id-0')) {
  289. document.getElementById('loading-id-0').parentNode.removeChild(document.getElementById('loading-id-0'))
  290. }
  291. var loadingContainerDOM = document.createElement('div');
  292. loadingContainerDOM.setAttribute('id', 'loading-id-0');
  293. var style = 'position:absolute;outline:none;'
  294. style += 'width: 0px;'
  295. style += 'height: 0px;'
  296. style += 'top:' + offsetTop + 'px;'
  297. style += 'left:' + offsetLeft + 'px;'
  298. loadingContainerDOM.setAttribute('style', style);
  299. var loadingContainer = document.getElementById("loading-id-0");
  300. loadingContainerDOM.style.height = windowHeight;
  301. loadingContainerDOM.setAttribute('class', 'loading-container');
  302. insertAfter(loadingContainerDOM, domElement);
  303. var splitBasis = playParams.splitBasis || 1;
  304. var windowLength = playParams.url.split(",").length;
  305. var loadingContainer = document.createElement('div');
  306. var loadingStatusDOM = document.createElement('div');
  307. loadingContainer.setAttribute('class', 'loading-item');
  308. loadingContainer.setAttribute('id', 'loading-item-' + i);
  309. //loadingContainer.setAttribute('style','display:inline-flex;flex-direction:column;justify-content:center;align-items: center;width:'+(windowWidth / splitBasis)+'px;height:'+(windowHeight /splitBasis )+'px;outline:none;vertical-align: top;position:absolute');
  310. var style = 'display:inline-flex;flex-direction:column;justify-content:center;align-items: center;width:' + (windowWidth / splitBasis) + 'px;height:' + (windowHeight / splitBasis) + 'px;outline:none;vertical-align: top;position:absolute;';
  311. style += ('left:' + calLoadingPostion(windowHeight, windowWidth, splitBasis, i).left + 'px;');
  312. style += ('top:' + calLoadingPostion(windowHeight, windowWidth, splitBasis, i).top + 'px;');
  313. loadingContainer.setAttribute('style', style);
  314. function calLoadingPostion(windowHeight, windowWidth, splitBasis, i) {
  315. var top = parseInt(i / splitBasis, 10) * (windowHeight / splitBasis);
  316. var left = (i % splitBasis) * (windowWidth / splitBasis);
  317. return {
  318. top: top,
  319. left: left
  320. }
  321. }
  322. var loadingDOM = document.createElement('div');
  323. loadingStatusDOM.innerHTML = "";
  324. loadingStatusDOM.style.color = "#fff";
  325. loadingDOM.setAttribute('class', type);
  326. var icon = '';
  327. switch (type) {
  328. case 'retry':
  329. icon = '<svg t="1590935684181" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1623" width="32" height="32"><path d="M972.8 102.4c-30.72 0-51.2 20.48-51.2 51.2v51.2c-51.2-71.68-122.88-128-204.8-158.72C460.8-66.56 158.72 51.2 46.08 307.2S51.2 865.28 307.2 977.92 865.28 972.8 977.92 716.8H972.8c0-30.72-20.48-51.2-51.2-51.2s-51.2 20.48-51.2 51.2h-5.12c-46.08 76.8-112.64 138.24-199.68 174.08-209.92 87.04-445.44-15.36-532.48-225.28S148.48 215.04 358.4 133.12c189.44-81.92 404.48 0 506.88 174.08H768c-30.72 0-51.2 20.48-51.2 51.2s20.48 51.2 51.2 51.2h204.8c30.72 0 51.2-20.48 51.2-51.2V153.6c0-30.72-20.48-51.2-51.2-51.2z" p-id="1624" fill="#ffffff"></path></svg>';
  330. loadingDOM.style.cursor = 'pointer';
  331. loadingDOM.onclick = function () {
  332. console.log("点击重试", i);
  333. // _this.loadingStart();
  334. _this.play(i);
  335. }
  336. break;
  337. }
  338. loadingDOM.innerHTML = icon;
  339. loadingContainer.appendChild(loadingDOM);
  340. loadingContainer.appendChild(loadingStatusDOM);
  341. loadingContainerDOM.appendChild(loadingContainer)
  342. }
  343. }
  344. this.loadingEnd = function (index) {
  345. var loadingItemContainerDOM = document.getElementById('loading-item-' + index);
  346. if (loadingItemContainerDOM) {
  347. loadingItemContainerDOM.parentNode.removeChild(loadingItemContainerDOM);
  348. var loadingContainerDOM = document.getElementById('loading-id-0');
  349. if (loadingContainerDOM && loadingContainerDOM.children.length === 0) {
  350. loadingContainerDOM.parentNode.removeChild(loadingContainerDOM);
  351. }
  352. }
  353. }
  354. // 将播放地址配置在实例 opt 属性中
  355. this.opt.sources.push(playParams.url);
  356. // JSDecoder 只有一个播放地址
  357. this.opt.currentSource = this.opt.sources[0];
  358. /* 获取解码器用户配置项 - 开始 */
  359. /**
  360. * 调试模式配置
  361. * 可通过dev属性指定API服务域名
  362. */
  363. var domain = "https://open.ys7.com";
  364. if (playParams.env) {
  365. var environmentParams = playParams.env;
  366. domain = environmentParams.domain;
  367. }
  368. /** 创建jSPlugin 对象 */
  369. this.jSPlugin = {};
  370. var _this = this;
  371. /** 根据播放参数获取真实播放地址 */
  372. this.loadingStart();
  373. playStartTime = new Date().getTime();
  374. // var getRealUrl = this.getRealUrl(playParams);
  375. var initDecoder = this.initDecoder(playParams);
  376. // 初始化播放器
  377. _this.loadingSet(0, { text: '初始化播放器...' });
  378. if(playParams.autoplay){
  379. _this.play()
  380. }
  381. if (isPromise(initDecoder)) {
  382. initDecoder.then(function (data) {
  383. _this.loadingSet(0, { text: '初始化完成' });
  384. // setTimeout(function () {
  385. // _this.play(playParams);
  386. // }, 100)
  387. // var getRealUrl = _this.getRealUrl(playParams);
  388. // getRealUrl.then(function (data) {
  389. // _this.play(playParams);
  390. // })
  391. })
  392. }
  393. // debugger
  394. /**是否自动播放 */
  395. // if (isPromise(getRealUrl)) {
  396. // getRealUrl.then(function (data) {
  397. // var initDecoder = _this.initDecoder(playParams);
  398. // // 初始化播放器
  399. // _this.loadingSet(0, { text: '初始化播放器...' });
  400. // if (isPromise(initDecoder)) {
  401. // initDecoder.then(function (data) {
  402. // _this.loadingSet(0, { text: '初始化完成' });
  403. // setTimeout(function () {
  404. // _this.play(playParams);
  405. // }, 1500)
  406. // })
  407. // }
  408. // })
  409. // }
  410. } else {
  411. var domain = "https://open.ys7.com";
  412. var elementID = '';
  413. if (typeof playParams === 'string') { //缩写模式 new EZUIPlayer('myplayer')
  414. elementID = playParams;
  415. } else if (typeof playParams === 'object') { //标准模式 new EZUIPlayer({id: 'myplayer'})
  416. elementID = playParams.id;
  417. }
  418. this.videoId = elementID;
  419. this.video = document.getElementById(elementID);
  420. if (!this.video) {
  421. throw new Error('EZUIPlayer requires parameter videoId');
  422. }
  423. var sources = this.video.getElementsByTagName('source');
  424. // 转为数组对象,不受removeChild影响
  425. sources = Array.prototype.slice.call(sources, 0);
  426. if (this.video.src) {
  427. // 移动端删除rtmp地址
  428. if (isMobile && RTMP_REG.test(this.video.src)) {
  429. this.video.removeAttribute('src');
  430. this.video.load();
  431. } else {
  432. this.opt.sources.push(this.video.src);
  433. }
  434. }
  435. var l = sources.length;
  436. if (l > 0) {
  437. for (var i = 0; i < l; i++) {
  438. // 移动端删除rtmp地址
  439. if (isMobile && RTMP_REG.test(sources[i].src)) {
  440. this.video.removeChild(sources[i]);
  441. } else {
  442. this.opt.sources.push(sources[i].src);
  443. }
  444. }
  445. }
  446. if (this.opt.sources.length < 1) {
  447. throw new Error('no source found in video tag.');
  448. }
  449. this.opt.cur = 0;
  450. this.opt.poster = this.video.poster;
  451. var videoStyle = getStyle(this.video);
  452. var width = this.video.width;
  453. var height = this.video.height;
  454. if (width) {
  455. this.opt.width = width;
  456. if (height) {
  457. this.opt.height = height;
  458. } else {
  459. this.opt.height = 'auto';
  460. }
  461. this.log('video width:' + this.opt.width + ' height:' + this.opt.height);
  462. } else {
  463. this.opt.width = videoStyle.width;
  464. this.opt.height = videoStyle.height;
  465. this.log('videoStyle.width:' + videoStyle.width + ' wideoStyle.height:' + videoStyle.height);
  466. }
  467. this.opt.parentId = elementID;
  468. this.opt.autoplay = this.video.autoplay ? true : false;
  469. this.log('autoplay:' + this.video.autoplay);
  470. this.opt.currentSource = this.opt.sources[this.opt.cur];
  471. this.getRealUrl(playParams);
  472. }
  473. /* 创建播放,错误,停止事件钩子,上报用户行为 */
  474. this.handlers = {};
  475. this.initTime = (new Date()).getTime();
  476. this.on('play', function () {
  477. // 上报播放成功信息
  478. dclog({
  479. systemName: PLAY_MAIN,
  480. playurl: this.opt.currentSource,
  481. Time: (new Date()).Format('yyyy-MM-dd hh:mm:ss.S'),
  482. Enc: 0, // 0 不加密 1 加密
  483. PlTp: 1, // 1 直播 2 回放
  484. Via: 911, // 2 私有流 911 标准流
  485. ErrCd: 0,
  486. OpId: uuid(),
  487. Cost: (new Date()).getTime() - this.initTime // 毫秒数
  488. });
  489. });
  490. this.retry = 2;
  491. this.on('error', function () {
  492. dclog({
  493. systemName: PLAY_MAIN,
  494. playurl: this.opt.currentSource,
  495. cost: -1,
  496. ErrCd: -1,
  497. Via: 911, // 2 私有流 911 标准流
  498. OpId: uuid(),
  499. });
  500. });
  501. var appInfoSuccess = function (data) {
  502. if (data.retcode === 0 && data.data) {
  503. appKey = data.data.appKey;
  504. }
  505. // 上报一次本地信息
  506. dclog({
  507. systemName: LOCALINFO,
  508. });
  509. // 上报一次本地信息-新
  510. ezuikitDclog({
  511. systemName: LOCALINFO_EZUIKIT,
  512. os: navigator.platform,
  513. browser: JSON.stringify(getBrowserInfo()),
  514. })
  515. }
  516. var appInfoError = function (error) {
  517. // 上报一次本地信息
  518. dclog({
  519. systemName: LOCALINFO
  520. });
  521. // 上报一次本地信息-新
  522. ezuikitDclog({
  523. systemName: LOCALINFO_EZUIKIT,
  524. os: navigator.platform,
  525. browser: JSON.stringify(getBrowserInfo()),
  526. })
  527. }
  528. var deviceSerial = '';
  529. var playUid = '';
  530. var accessToken = '';
  531. var uuidReg = /[a-z0-9]{32}/;
  532. var deviceSerialReg = /[a-zA-Z0-9]{9}\/[0-9]{0,2}\./;
  533. if (typeof playParams === 'string') {
  534. var url = this.opt.currentSource;
  535. if (uuidReg.test(url)) {
  536. playUid = url.match(uuidReg)[0];
  537. } else if (deviceSerialReg.test(url)) {
  538. deviceSerial = url.match(deviceSerialReg)[0].split('/')[0];
  539. }
  540. } else if (typeof playParams === 'object') {
  541. var url = playParams.url;
  542. if (uuidReg.test(url)) {
  543. playUid = url.match(uuidReg);
  544. } else if (deviceSerialReg.test(url)) {
  545. deviceSerial = url.match(deviceSerialReg)[0].split('/')[0];
  546. }
  547. if (playParams.accessToken) {
  548. accessToken = playParams.accessToken;
  549. }
  550. }
  551. // 获取appKey
  552. request(domain + '/jssdk/ezopen/getAppInfo?uuid=' + playUid + '&accessToken=' + accessToken + "&deviceSerial=" + deviceSerial + "&channelNo=1",
  553. 'GET',
  554. '',
  555. '',
  556. appInfoSuccess,
  557. appInfoError
  558. );
  559. };
  560. // 事件监听
  561. EZUIPlayer.prototype.on = function (eventName, callback) {
  562. if (typeof eventName !== 'string' || typeof callback !== 'function') {
  563. return;
  564. }
  565. if (typeof this.handlers[eventName] === 'undefined') {
  566. this.handlers[eventName] = [];
  567. }
  568. this.handlers[eventName].push(callback);
  569. };
  570. // 事件触发
  571. EZUIPlayer.prototype.emit = function () {
  572. if (this.handlers[arguments[0]] instanceof Array) {
  573. var handlers = this.handlers[arguments[0]];
  574. var l = handlers.length;
  575. for (var i = 0; i < l; i++) {
  576. handlers[i].apply(this, Array.prototype.slice.call(arguments, 1));
  577. }
  578. }
  579. };
  580. // 日志
  581. EZUIPlayer.prototype.log = function (msg, className) {
  582. this.emit('log', msg, className);
  583. };
  584. EZUIPlayer.prototype.getRealUrl = function (playParams) {
  585. var _this = this;
  586. var apiDomain = 'https://open.ys7.com';
  587. if (playParams && playParams.env) {
  588. apiDomain = playParams.env.domain;
  589. }
  590. /** jsDecoder 获取真实地址 -- 开始 */
  591. if (playParams && playParams.hasOwnProperty('decoderPath')) {
  592. if (playParams && playParams.hasOwnProperty('userName') && playParams.hasOwnProperty('password')) {
  593. // var cryJS = '/js/cryptico.min.js';
  594. // addJs(cryJS, function () { })
  595. console.log("开始播放局域网");
  596. getRealUrlPromise = function (resolve, reject, ezopenURL) {
  597. // var realUrl = 'ws://10.11.36.57:7681/101?sessionID=64faad6d7e2ac432a623404914ecc9997ea8533cd1f71e6e72548104b1d7279f';
  598. // resolve(realUrl);
  599. var realUrl = '';
  600. // 向API请求真实地址
  601. var apiUrl = apiDomain + "/api/lapp/v2/live/laninfo/get";
  602. var apiSuccess = function (data) {
  603. if (data.code == 200 || data.retcode == 0) {
  604. //realUrl += 'ws://' + data.data.localIp + ':' + data.data.wssLocalPort + '10' + (playParams.url.indexOf('hd') === -1 ? '2' : '1');
  605. //test -start
  606. data.data.localIp = '10.11.51.53';
  607. apiDomain = 'http://y.ys7.com:3100';
  608. // test-end
  609. realUrl += 'ws://' + data.data.localIp + ':' + data.data.wssLocalPort + '/' + '10' + (playParams.url.indexOf('hd') === -1 ? '2' : '1');
  610. // 执行设备授权
  611. capabilitiesUrl = apiDomain + "/jssdk/ezopen/sessionLogin/capabilities?ip=" + data.data.localIp + "&username=" + playParams.userName
  612. var capabilitiesSuccess = function (xmlDoc, textStatus, xhr) {
  613. console.log("xmlDoc", xmlDoc, xmlDoc.split('<sessionID>'))
  614. var userName = playParams.userName;
  615. var password = playParams.password;
  616. var sessionIDReg = /<sessionID>(.*)<\/sessionID>/i;
  617. var challengeReg = /<challenge>(.*)<\/challenge>/i;
  618. var iterationsReg = /<iterations>(.*)<\/iterations>/i;
  619. var isIrreversibleReg = /<isIrreversible>(.*)<\/isIrreversible>/i;
  620. var saltReg = /<salt>(.*)<\/salt>/i;
  621. var sessionID = sessionIDReg.exec(xmlDoc)[1];
  622. var challenge = challengeReg.exec(xmlDoc)[1];
  623. var iterations = iterationsReg.exec(xmlDoc)[1];
  624. var isIrreversible = isIrreversibleReg.exec(xmlDoc)[1] == 'true';
  625. var salt = saltReg.exec(xmlDoc)[1];
  626. console.log(sessionID, challenge, iterations, isIrreversible, salt)
  627. var szEncryptedPwd = '';
  628. if (!isIrreversible) {
  629. szEncryptedPwd = SHA256(password) + challenge;
  630. for (var i = 1; i < iterations; i++) {
  631. szEncryptedPwd = SHA256(szEncryptedPwd);
  632. }
  633. } else {
  634. szEncryptedPwd = SHA256(userName + salt + password);
  635. szEncryptedPwd = SHA256(szEncryptedPwd + challenge);
  636. for (var i = 2; i < iterations; i++) {
  637. szEncryptedPwd = SHA256(szEncryptedPwd);
  638. }
  639. }
  640. console.log("szEncryptedPwd", szEncryptedPwd)
  641. // // session登录
  642. // var loginUrl = 'http://y.ys7.com:3100/jssdk/ezopen/sessionLogin?ip=' + '10.11.36.57' + '&encryptedPwd=' + szEncryptedPwd + '&sessionID=' + sessionID;
  643. // var loginSuccess = function (data) {
  644. // // debugger;
  645. // }
  646. // var loginError = function (err) {
  647. // }
  648. // // debugger
  649. // request(loginUrl, 'GET', null, '', loginSuccess, loginError);
  650. $.ajax({
  651. url: apiDomain + '/jssdk/ezopen/sessionLogin',
  652. type: "post",
  653. data: {
  654. ip: data.data.localIp,
  655. authXml: "<SessionLogin><userName>" + playParams.userName + "</userName><password>" + szEncryptedPwd + "</password><sessionID>" + sessionID + "</sessionID>\r\n\t<isSessionIDValidLongTerm>false</isSessionIDValidLongTerm>\r\n\t<sessionIDVersion>2</sessionIDVersion>\r\n</SessionLogin>",
  656. },
  657. success: function (data) {
  658. console.log("data", data);
  659. szWebsocketSessionID = data.WebSession.split("=")[1].split(";")[0];
  660. realUrl += '?sessionID=' + szWebsocketSessionID;
  661. resolve(realUrl);
  662. },
  663. error: function (xhr, textStatus, errorThrown) {
  664. alert("error");
  665. }
  666. })
  667. }
  668. var deviceSerialReg = /[a-zA-Z0-9]{9}\/[0-9]{0,2}\./;
  669. var deviceSerial = playParams.url.match(deviceSerialReg)[0].split('/')[0];
  670. var capabilitiesError = function (error) {
  671. // 将错误信息捕获到用户自定义错误回调中
  672. if (playParams && playParams.handleError) {
  673. playParams.handleError(error);
  674. }
  675. }
  676. request(capabilitiesUrl, 'GET', {}, '', capabilitiesSuccess, capabilitiesError);
  677. }
  678. }
  679. var deviceSerialReg = /[a-zA-Z0-9]{9}\/[0-9]{0,2}\./;
  680. var deviceSerial = playParams.url.match(deviceSerialReg)[0].split('/')[0];
  681. var apiParams = {
  682. deviceSerial: deviceSerial,
  683. accessToken: playParams.accessToken,
  684. }
  685. var apiError = function (error) {
  686. // 将错误信息捕获到用户自定义错误回调中
  687. if (playParams && playParams.handleError) {
  688. playParams.handleError(error);
  689. }
  690. }
  691. request(apiUrl, 'POST', apiParams, '', apiSuccess, apiError);
  692. }
  693. var urlList = playParams.url.split(',')
  694. var promiseTaskList = [];
  695. var promiseTaskFun = function (ezopenURL) {
  696. return new Promise(function (resolve, reject) { return getRealUrlPromise(resolve, reject, ezopenURL) })
  697. };
  698. urlList.map(function (item, index) {
  699. _this.loadingSet(index, { text: '获取设备播放地址' })
  700. promiseTaskList.push(promiseTaskFun(item));
  701. });
  702. var getRealUrlPromiseObj = Promise.all(promiseTaskList)
  703. .then(function (result) {
  704. // debugger
  705. // 获取真实地址成功后,赋值到opt属性中
  706. _this.opt.sources = result;
  707. _this.opt.currentSource = result[0];
  708. result.forEach(function (item, index) {
  709. _this.loadingSet(index, { text: '获取播放地址成功' })
  710. })
  711. })
  712. .catch(function (err) {
  713. // debugger
  714. _this.log("获取真实地址错误" + JSON.stringify(err), 'error')
  715. })
  716. return getRealUrlPromiseObj;
  717. } else {
  718. // api 获取真实地址开始时间
  719. var getRealUrlDurationST = new Date().getTime();
  720. var getRealUrlPromise = function (resolve, reject, ezopenURL) {
  721. var realUrl = '';
  722. if (!/^ezopen:\/\//.test(ezopenURL)) { // JSDecoder ws协议播放
  723. resolve(ezopenURL);
  724. } else {
  725. // var getPlayTokenST = new Date().getTime();
  726. // var nodeUrl = apiDomain + "/jssdk/ezopen/getStreamToken?accessToken=" + playParams.accessToken + '&num=10&type=' + (playParams.url.indexOf('live') !== -1 ? 'live' : 'playback');
  727. // var nodeSuccess = function (data) {
  728. // if (data.retcode === 0) {
  729. // realUrl = realUrl + data.data.params + '&ssn=' + data.data.tokens[0];
  730. // // _this.opt.currentSource = realUrl;
  731. // ezuikitDclog({
  732. // systemName: PERFORMANCE_EZUIKIT,
  733. // bn: 3,
  734. // browser: JSON.stringify(getBrowserInfo()),
  735. // duration: new Date().getTime() - getPlayTokenST,
  736. // rt: 200,
  737. // })
  738. // resolve(realUrl);
  739. // } else {
  740. // // 将错误信息捕获到用户自定义错误回调中
  741. // if (playParams && playParams.handleError) {
  742. // playParams.handleError(data);
  743. // }
  744. // // 错误信息显示在状态中
  745. // if (data.msg) {
  746. // _this.loadingSet(0, { text: data.msg, color: 'red' });
  747. // }
  748. // ezuikitDclog({
  749. // systemName: PERFORMANCE_EZUIKIT,
  750. // bn: 3,
  751. // browser: JSON.stringify(getBrowserInfo()),
  752. // duration: new Date().getTime() - getPlayTokenST,
  753. // rt: data.retcode,
  754. // msg: data.msg,
  755. // })
  756. // resolve(JSON.stringify(data));
  757. // throw new Error('获取播放token失败');
  758. // }
  759. // }
  760. // var nodeError = function (error) {
  761. // // 将错误信息捕获到用户自定义错误回调中
  762. // if (playParams && playParams.handleError) {
  763. // playParams.handleError(error);
  764. // }
  765. // ezuikitDclog({
  766. // systemName: PERFORMANCE_EZUIKIT,
  767. // bn: 3,
  768. // browser: JSON.stringify(getBrowserInfo()),
  769. // duration: new Date().getTime() - getPlayTokenST,
  770. // rt: 500,
  771. // msg: '获取取流token网络错误',
  772. // })
  773. // resolve(JSON.stringify(error))
  774. // throw new Error('获取播放token失败', 'error');
  775. // }
  776. // 向API请求真实地址
  777. var apiUrl = apiDomain + "/api/lapp/live/url/ezopen";
  778. var apiSuccess = function (data) {
  779. if (data.code == 200 || data.retcode == 0) {
  780. realUrl += data.data;
  781. if(data.ext && data.ext.token){
  782. stream = data.ext.token;
  783. var type= playParams.url.indexOf('live') !== -1 ? 'live' : 'playback';
  784. if(type === 'live'){
  785. realUrl = realUrl + '&auth=1&biz=4&cln=100' + '&ssn=' + stream;
  786. }else {
  787. realUrl = realUrl + '&auth=1&cln=100' + '&ssn=' + stream;
  788. }
  789. console.log(realUrl)
  790. }
  791. /**参数容错处理 start*/
  792. if (data.data.indexOf('playback') !== -1) { //回放
  793. var wsBegin = getQueryString('begin', data.data) || getQueryString('begin', playParams.url);
  794. var wsEnd = getQueryString('end', data.data) || getQueryString('end', playParams.url);
  795. // 兼容各种时间格式
  796. if (!wsBegin) {
  797. var defaultDate = new Date();
  798. realUrl = realUrl + '&begin=' + defaultDate.Format('yyyyMMdd') + 'T000000Z';
  799. } else {
  800. realUrl = realUrl.replace('&begin=' + getQueryString('begin', data.data), '&begin=' + formatRecTime(wsBegin, '000000'))
  801. if(!getQueryString('begin',realUrl)){
  802. realUrl += '&begin=' + formatRecTime(wsBegin, '000000');
  803. }
  804. }
  805. if (!wsEnd) {
  806. var defaultDate = new Date();
  807. realUrl = realUrl + '&end=' + defaultDate.Format('yyyyMMdd') + 'T235959Z';
  808. } else {
  809. realUrl = realUrl.replace('&end=' + getQueryString('end', data.data), '&end=' + formatRecTime(wsEnd, '235959'))
  810. if(!getQueryString('end',realUrl)){
  811. realUrl += '&end=' + formatRecTime(wsEnd, '235959');
  812. }
  813. }
  814. // api错误处理
  815. if (!getQueryString('stream', data.data)) {
  816. realUrl = realUrl.replace('stream', '&stream');
  817. }
  818. if (playParams.url.indexOf('.cloud') !== -1) {
  819. // 调用回放API接口获取回放片段 - start
  820. var recBegin = reRormatRecTime(getQueryString('begin', realUrl));
  821. var recEnd = reRormatRecTime(getQueryString('end', realUrl));
  822. var deviceSerial = getQueryString('serial', realUrl)
  823. var channelNo = getQueryString('chn', realUrl);
  824. var recSliceUrl = apiDomain + "/api/lapp/video/by/time";
  825. var recSliceParams = {
  826. accessToken: playParams.accessToken,
  827. recType: 1,
  828. deviceSerial: deviceSerial,
  829. channelNo: channelNo,
  830. startTime: recBegin,
  831. endTime: recEnd
  832. }
  833. function recAPISuccess(data) {
  834. if (data.code == 200) {
  835. var recSliceArr = [];
  836. if (data.data && data.data.length > 0) {
  837. recSliceArr = recSliceArrFun(data.data);
  838. var recSliceArrJSON = JSON.stringify(recSliceArr).replace('\\', '');
  839. realUrl += ('&recSlice=' + recSliceArrJSON.replace('\\', ''));
  840. // request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError);
  841. resolve(realUrl);
  842. } else {
  843. _this.log('未找到录像片段', 'error');
  844. _this.loadingSet(0, { text: '获取设备播放地址' })
  845. resolve(JSON.stringify({ code: -1, msg: "未找到录像片段" }))
  846. // reject('未找到录像片段');
  847. }
  848. } else {
  849. _this.log(data.msg, 'error');
  850. _this.loadingSet(0, { text: '获取设备播放地址' });
  851. resolve(JSON.stringify({ code: -1, msg: "未找到录像片段" }))
  852. //reject('未找到录像片段');
  853. }
  854. function recSliceArrFun(data) {
  855. var downloadPathArr = [];
  856. var currentDP = downloadPathArr.length
  857. data.forEach(function (item, index) {
  858. if (downloadPathArr.length == 0 || (item.downloadPath !== downloadPathArr[downloadPathArr.length - 1].downloadPath)) {
  859. downloadPathArr.push({
  860. downloadPath: item.downloadPath,
  861. ownerId: item.ownerId,
  862. iStorageVersion: item.iStorageVersion,
  863. videoType: item.videoType,
  864. iPlaySpeed: 0,
  865. startTime: item.startTime,
  866. endTime: item.endTime
  867. })
  868. } else {
  869. downloadPathArr[downloadPathArr.length - 1].endTime = item.endTime;
  870. }
  871. })
  872. return downloadPathArr;
  873. }
  874. }
  875. function recAPIError(err) {
  876. console.log("获取回放片段错误")
  877. }
  878. request(recSliceUrl, 'POST', recSliceParams, '', recAPISuccess, recAPIError);
  879. } else {// 本地回放
  880. //alarm rec - start
  881. if (playParams.url.indexOf('alarmId') !== -1) {
  882. console.log("进入alarmId回放")
  883. // 调用回放API接口获取回放片段 - start
  884. var alarmId = getQueryString('alarmId', realUrl)
  885. var recBegin = reRormatRecTime(getQueryString('begin', realUrl));
  886. var recEnd = reRormatRecTime(getQueryString('end', realUrl));
  887. var deviceSerial = getQueryString('serial', realUrl)
  888. var channelNo = getQueryString('chn', realUrl);
  889. var recSliceUrl = apiDomain + "/api/lapp/video/by/id";
  890. var recSliceParams = {
  891. accessToken: playParams.accessToken,
  892. // recType: 1,
  893. deviceSerial: deviceSerial,
  894. channelNo: channelNo,
  895. alarmId: alarmId,
  896. // startTime:recBegin,
  897. // endTime:recEnd
  898. }
  899. function recAPISuccess(data) {
  900. if (data.code == 200) {
  901. var recSliceArr = [];
  902. if (data.data) {
  903. recSliceArr = recSliceArrFun([data.data]);
  904. var recSliceArrJSON = JSON.stringify(recSliceArr).replace('\\', '');
  905. realUrl += ('&recSlice=' + recSliceArrJSON.replace('\\', ''));
  906. console.log("realUrl", realUrl, data.data.recType);
  907. if (data.data.recType == 1) {
  908. realUrl = realUrl.replace('/playback', '/cloudplayback')
  909. } else {
  910. realUrl = realUrl.replace('/cloudplayback', '/playback')
  911. }
  912. _this.opt.sources[0] = realUrl;
  913. resolve(realUrl);
  914. // request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError);
  915. } else {
  916. _this.log('未找到录像片段', 'error');
  917. _this.loadingSet(0, { text: '获取设备播放地址' })
  918. resolve(JSON.stringify({ code: -1, msg: "未找到录像片段" }))
  919. // reject('未找到录像片段');
  920. }
  921. } else {
  922. _this.log(data.msg, 'error');
  923. _this.loadingSet(0, { text: '获取设备播放地址' });
  924. resolve(JSON.stringify({ code: -1, msg: "未找到录像片段" }))
  925. //reject('未找到录像片段');
  926. }
  927. function recSliceArrFun(data) {
  928. var downloadPathArr = [];
  929. var currentDP = downloadPathArr.length
  930. data.forEach(function (item, index) {
  931. if (downloadPathArr.length == 0 || (item.downloadPath !== downloadPathArr[downloadPathArr.length - 1].downloadPath)) {
  932. downloadPathArr.push({
  933. downloadPath: item.downloadPath,
  934. ownerId: item.ownerId,
  935. iStorageVersion: item.iStorageVersion,
  936. videoType: item.videoType,
  937. iPlaySpeed: 0,
  938. startTime: item.startTime,
  939. endTime: item.endTime
  940. })
  941. } else {
  942. downloadPathArr[downloadPathArr.length - 1].endTime = item.endTime;
  943. }
  944. })
  945. console.log("downloadPathArr", downloadPathArr)
  946. return downloadPathArr;
  947. }
  948. }
  949. function recAPIError(err) {
  950. console.log("获取回放片段错误")
  951. }
  952. request(recSliceUrl, 'POST', recSliceParams, '', recAPISuccess, recAPIError);
  953. } else {
  954. // arlar rec - end
  955. // request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError);
  956. resolve(realUrl);
  957. }
  958. }
  959. } else {
  960. // 预览直接获取回放片段
  961. // request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError);
  962. resolve(realUrl);
  963. }
  964. getPlayTokenST = new Date().getTime();
  965. // 执行一次API服务请求上报
  966. var getRealUrlDurationET = new Date().getTime();
  967. ezuikitDclog({
  968. systemName: PERFORMANCE_EZUIKIT,
  969. bn: 0,
  970. browser: JSON.stringify(getBrowserInfo()),
  971. duration: getRealUrlDurationET - getRealUrlDurationST,
  972. rt: 200,
  973. })
  974. } else {
  975. // 将错误信息捕获到用户自定义错误回调中
  976. if (playParams && playParams.handleError) {
  977. playParams.handleError(Object.assign({retcode: data.code || -1,msg: data.msg || '其他错误'}));
  978. }
  979. // 执行一次API服务请求服务错误上报
  980. var getRealUrlDurationET = new Date().getTime();
  981. ezuikitDclog({
  982. systemName: PERFORMANCE_EZUIKIT,
  983. bn: 0,
  984. browser: JSON.stringify(getBrowserInfo()),
  985. duration: getRealUrlDurationET - getRealUrlDurationST,
  986. rt: data.code || 500,
  987. msg: data.msg || '未知服务错误'
  988. })
  989. resolve(JSON.stringify(data), 'error')
  990. //throw new Error('获取播放设备信息失败');
  991. }
  992. /**参数容错处理 end*/
  993. }
  994. var apiError = function (error) {
  995. // 将错误信息捕获到用户自定义错误回调中
  996. if (playParams && playParams.handleError) {
  997. playParams.handleError(Object.assign({retcode: error.code || -1,msg: error.msg || '其他错误'}));
  998. }
  999. var getRealUrlDurationET = new Date().getTime();
  1000. ezuikitDclog({
  1001. systemName: PERFORMANCE_EZUIKIT,
  1002. bn: 0,
  1003. browser: JSON.stringify(getBrowserInfo()),
  1004. duration: getRealUrlDurationET - getRealUrlDurationST,
  1005. rt: 500,
  1006. msg: data.msg || '网络错误'
  1007. })
  1008. resolve(JSON.stringify(error))
  1009. //throw new Error('获取播放设备信息失败');
  1010. }
  1011. var isHttp = 'false';
  1012. if (playParams && playParams.env && playParams.env.domain) {
  1013. isHttp = playParams.env.domain.indexOf('https') !== -1 ? 'false' : 'true';
  1014. } else {
  1015. isHttp = window.location.href.indexOf('https') !== -1 ? 'false' : 'true';
  1016. }
  1017. var apiParams = {
  1018. ezopen: ezopenURL,
  1019. userAgent: window.navigator.userAgent,
  1020. isFlv: false,
  1021. addressTypes: null,
  1022. isHttp: isHttp,
  1023. accessToken: playParams.accessToken,
  1024. }
  1025. request(apiUrl, 'POST', apiParams, '', apiSuccess, apiError);
  1026. }
  1027. }
  1028. var urlList = playParams.url.split(',')
  1029. var promiseTaskList = [];
  1030. var promiseTaskFun = function (ezopenURL) {
  1031. return new Promise(function (resolve, reject) { return getRealUrlPromise(resolve, reject, ezopenURL) })
  1032. };
  1033. urlList.map(function (item, index) {
  1034. _this.loadingSet(index, { text: '获取设备播放地址' })
  1035. promiseTaskList.push(promiseTaskFun(item));
  1036. });
  1037. var getRealUrlPromiseObj = Promise.all(promiseTaskList)
  1038. .then(function (result) {
  1039. // 获取真实地址成功后,赋值到opt属性中
  1040. _this.opt.sources = result;
  1041. _this.opt.currentSource = result[0];
  1042. result.forEach(function (item, index) {
  1043. _this.loadingSet(index, { text: '获取播放地址成功' })
  1044. })
  1045. })
  1046. .catch(function (err) {
  1047. _this.log("获取真实地址错误" + JSON.stringify(err), 'error')
  1048. })
  1049. return getRealUrlPromiseObj;
  1050. }
  1051. } else {
  1052. if (!this.opt.currentSource) {
  1053. this.log('未找到合适的播放URL', 'error');
  1054. return;
  1055. }
  1056. var me = this;
  1057. // 如果不是ezopen打头的,走原来的播放模式
  1058. if (!/^ezopen:\/\//.test(this.opt.currentSource)) {
  1059. this.tryPlay(this.opt.currentSource);
  1060. } else {
  1061. // 如果是ezopen协议地址,先校验一下地址的合法性
  1062. if (!/^ezopen:\/\//.test(this.opt.currentSource)) {
  1063. throw new Error('EZOPEN地址必须要以ezopen://开头');
  1064. return;
  1065. } else if (this.opt.currentSource.indexOf('.com/') === -1) {
  1066. throw new Error('EZOPEN地址格式不正确');
  1067. return;
  1068. } else if (!/[a-z\d]{32}(\.hd)?\.live/.test(this.opt.currentSource)) {
  1069. throw new Error('EZOPEN地址格式uuid格式不正确');
  1070. return;
  1071. } else if (/(.*.hls.*|.*.m3u8.*|.*.wss.*|.*.flv.*|.*.rtmp.*){2,}/.test(this.opt.currentSource)) {
  1072. throw new Error('EZOPEN地址多于两个播放协议');
  1073. return;
  1074. } else if (this.opt.currentSource.search(/(.hls|.m3u8|.wss|.flv|.rtmp)/) !== -1 && !/.live(.hls|.m3u8|.wss|.flv|.rtmp)/.test(this.opt.currentSource)) {
  1075. throw new Error('请指定正确的播放协议');
  1076. return;
  1077. } else if (this.opt.currentSource.search(/(.hls|.m3u8|.wss|.flv|.rtmp)/) === -1 && !/[a-z\d]{32}(\.hd)?\.live$/.test(this.opt.currentSource)) {
  1078. throw new Error('EZOPEN地址结尾不正确');
  1079. return;
  1080. } else {
  1081. /* 获取播放地址 - 开始 */
  1082. var that = this;
  1083. addJs(flv_js, function () {
  1084. var para = {
  1085. "ezopen": that.opt.currentSource,
  1086. "userAgent": window.navigator.userAgent,
  1087. "isFlv": flvjs && flvjs.isSupported() ? flvjs.isSupported() : false,
  1088. "addressTypes": "HLS,RTMP,WS,FLV",
  1089. "isHttp": window.location.protocol.indexOf('s') > 0 ? false : true,
  1090. };
  1091. dclog({
  1092. "ezopen": that.opt.currentSource,
  1093. "userAgent": window.navigator.userAgent,
  1094. "isFlv": flvjs && flvjs.isSupported() ? flvjs.isSupported() : false,
  1095. "addressTypes": "HLS,RTMP,WS,FLV",
  1096. "isHttp": window.location.protocol.indexOf('s') > 0 ? false : true,
  1097. 'systemName': 'EZOPEN',
  1098. });
  1099. that.log('---------------------------------------');
  1100. that.log('入参(ezopen)是: ' + para.ezopen);
  1101. that.log('---------------------------------------');
  1102. that.log('入参(userAgent)是: ' + para.userAgent);
  1103. that.log('---------------------------------------');
  1104. that.log('入参(isFlv)是: ' + para.isFlv);
  1105. that.log('---------------------------------------');
  1106. that.log('入参(addressTypes)是: ' + para.addressTypes);
  1107. that.log('---------------------------------------');
  1108. that.log('入参(isHttp)是: ' + para.isHttp);
  1109. that.log('---------------------------------------');
  1110. var apiUrl = apiDomain + "/api/lapp/live/url/ezopen";
  1111. var apiSuccess = function (data) {
  1112. if (data.code == 200) {
  1113. that.log('播放地址是: ' + data.data);
  1114. that.video.src = data.data;
  1115. that.video.load();
  1116. that.tryPlay(data.data);
  1117. } else {
  1118. that.log('data: ' + JSON.stringify(data));
  1119. throw new Error(data.msg);
  1120. return;
  1121. }
  1122. }
  1123. var apiError = function (error) {
  1124. console.log("getdecoder url from api error", error);
  1125. }
  1126. request(apiUrl, 'POST', para, '', apiSuccess, apiError);
  1127. });
  1128. } /* 获取播放地址 - 结束 */
  1129. }
  1130. }
  1131. // 格式化回放时间
  1132. function formatRecTime(time, defaultTime) {
  1133. // 用户格式 无需更改 => 20182626T000000Z
  1134. // return time
  1135. // 用户格式需要更改
  1136. //用户时间长度为 14 20181226000000 =》 20181226000000
  1137. // 用户长度为12 201812260000 =》 201812260000 + defaultTime后面2位
  1138. // 用户长度为10 2018122600 =》 201812260000 + defaultTime后面4位
  1139. // 用户长度为8 20181226 =》 201812260000 + defaultTime后面6位
  1140. // 结果 20181226000000 14位
  1141. // 插入 TZ
  1142. var reg = /^[0-9]{8}T[0-9]{6}Z$/;
  1143. if (reg.test(time)) { // 用户格式 无需更改 => 20182626T000000Z
  1144. return time;
  1145. } else if (/[0-9]{8,14}/.test(time)) {
  1146. var start = 6 - (14 - time.length);
  1147. var end = defaultTime.length;
  1148. var standardTime = time + defaultTime.substring(start, end);
  1149. return standardTime.slice(0, 8) + 'T' + standardTime.slice(8) + 'Z';
  1150. } else {
  1151. throw new Error('回放时间格式有误,请确认');
  1152. }
  1153. }
  1154. function reRormatRecTime(time) {
  1155. var year = time.slice(0, 4);
  1156. var month = time.slice(4, 6);
  1157. var day = time.slice(6, 8);
  1158. var hour = time.slice(9, 11);
  1159. var minute = time.slice(11, 13);
  1160. var second = time.slice(13, 15);
  1161. var date = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
  1162. return new Date(date.replace(/-/g, '/')).getTime();
  1163. }
  1164. };
  1165. // 尝试播放
  1166. EZUIPlayer.prototype.tryPlay = function (playParams) {
  1167. this.log("开始尝试播放,播放配置参数为:");
  1168. this.log(playParams);
  1169. var _this = this;
  1170. // JSDecoder 播放
  1171. if (playParams && typeof playParams === 'object' && playParams.decoderPath) {
  1172. /** 初始化Decoder */
  1173. // this.initDecoder(playParams);
  1174. // 自动播放
  1175. // if(playParams.autoplay){
  1176. // console.log('配置了自动播放');
  1177. // setTimeout(function(){
  1178. // _this.play();
  1179. // },2000)
  1180. // }
  1181. } else {
  1182. this.opt.currentSource = playParams;
  1183. var me = this;
  1184. // 如果是HLS地址
  1185. if (/\.m3u8/.test(playParams)) {
  1186. // 如果是手机浏览器环境,或者原生支持HLS播放的,直接使用video标签播放
  1187. // 否则尝试使用hls.js播放,
  1188. // 最后使用flash
  1189. if (isMobile || isNativeSupportHls) {
  1190. this.log('使用原生video');
  1191. this.video.style.heght = this.opt.height = Number(this.opt.width.replace(/px$/g, '')) * 9 / 16 + 'px';
  1192. this.initVideoEvent();
  1193. } else {
  1194. var isPlayUrlHttps = playParams.indexOf('https') !== -1;
  1195. if (isHttps && !isPlayUrlHttps) { //https网站,http视频源安全问题需要flash播放
  1196. addJs(ckplayerJS, function () {
  1197. me.initCKPlayer();
  1198. });
  1199. } else {
  1200. addJs(hlsJS, function () {
  1201. isSupportHls = Hls.isSupported();
  1202. if (isSupportHls) {
  1203. me.log('使用hls.js');
  1204. me.initHLS(playParams);
  1205. } else {
  1206. useFlash = true;
  1207. me.log('2 使用flash');
  1208. addJs(ckplayerJS, function () {
  1209. me.initCKPlayer();
  1210. });
  1211. }
  1212. });
  1213. }
  1214. }
  1215. } else if (/^rtmp:/.test(playParams)) {
  1216. if (isMobile) {
  1217. this.opt.cur++;
  1218. this.tryPlay(playParams);
  1219. return;
  1220. } else {
  1221. addJs(ckplayerJS, function () {
  1222. me.initCKPlayer(playParams);
  1223. });
  1224. }
  1225. } else if (/^wss:|^ws:/.test(playParams)) {
  1226. /*
  1227. * WS协议的JSMpeg的不支持IE11以下的版本
  1228. * 开放平台官网不支持IE8打开,所以官网上面不兼容两个人版本IE9 ,和IE10
  1229. *
  1230. * */
  1231. if (!ltIE11()) {
  1232. addJs(mpegJS, function () {
  1233. me.initJSmpeg(playParams);
  1234. });
  1235. } else {
  1236. alert('WS协议不支持Ie11以下的浏览器!请使用IE11,或者更高版本的浏览器');
  1237. return;
  1238. }
  1239. } else if (/\.flv/.test(this.opt.currentSource)) {
  1240. if (!ltIE11()) {
  1241. addJs(ckplayerJS, function () {
  1242. me.initCKPlayer();
  1243. });
  1244. } else {
  1245. addJs(flv_js, function () {
  1246. me.log("使用flv.js播放");
  1247. me.initflv();
  1248. });
  1249. }
  1250. }
  1251. }
  1252. };
  1253. // 初始化hls.js
  1254. EZUIPlayer.prototype.initHLS = function (hlsURL) {
  1255. var me = this;
  1256. var hls = new Hls({ defaultAudioCodec: 'mp4a.40.2' }); // 萤石设备默认使用 AAC LC 音频编码
  1257. hls.loadSource(hlsURL);
  1258. hls.attachMedia(this.video);
  1259. hls.on(Hls.Events.MANIFEST_PARSED, function () {
  1260. if (me.opt.autoplay) {
  1261. me.video.play();
  1262. }
  1263. me.initVideoEvent();
  1264. });
  1265. hls.on(Hls.Events.ERROR, function (event, data) {
  1266. if (data.fatal) {
  1267. switch (data.type) {
  1268. case Hls.ErrorTypes.NETWORK_ERROR:
  1269. // try to recover network error
  1270. console.log("fatal network error encountered, try to recover");
  1271. hls.startLoad();
  1272. break;
  1273. case Hls.ErrorTypes.MEDIA_ERROR:
  1274. console.log("fatal media error encountered, try to recover");
  1275. hls.recoverMediaError();
  1276. break;
  1277. default:
  1278. // cannot recover
  1279. hls.destroy();
  1280. break;
  1281. }
  1282. }
  1283. });
  1284. this.hls = hls;
  1285. };
  1286. // 初始化ckplayer
  1287. EZUIPlayer.prototype.initCKPlayer = function (url) {
  1288. this.log('ckplayer初始化');
  1289. var me = this;
  1290. var events = {
  1291. 'play': function () { me.emit('play') },
  1292. 'pause': function () { me.emit('pause') },
  1293. 'error': function () { me.emit('error') }
  1294. };
  1295. window.ckplayer_status = function () {
  1296. me.log(arguments);
  1297. events[arguments[0]] && events[arguments[0]]();
  1298. };
  1299. // 新增相同id的div标签,然后删除video标签
  1300. this.videoFlash = document.createElement('DIV');
  1301. this.video.parentNode.replaceChild(this.videoFlash, this.video);
  1302. this.video = this.videoFlash;
  1303. this.videoFlash.id = this.opt.parentId;
  1304. var flashvars = null;
  1305. // 如果rtmp服务器环境设置了视频暂停则断开链接
  1306. // 需要修改ckplayer.js setup参数第30个值
  1307. // 在播放暂停后点击播放是否采用重新链接的方式
  1308. if (/^rtmp/.test(this.opt.currentSource)) {
  1309. flashvars = {
  1310. f: this.opt.currentSource,
  1311. c: 0,
  1312. p: this.opt.autoplay ? 1 : 0,
  1313. i: this.opt.poster,
  1314. lv: 1,
  1315. loaded: 'loadHandler'
  1316. };
  1317. } else if (/\.m3u8/.test(this.opt.currentSource)) {
  1318. flashvars = {
  1319. s: 4, // 4-使用swf视频流插件播放
  1320. f: m3u8SWF,
  1321. a: this.opt.currentSource,
  1322. c: 0, // 0-使用ckplayer.js的配置 1-使用ckplayer.xml的配置
  1323. lv: 1, // 1-直播 0-普通方式
  1324. p: this.opt.autoplay ? 1 : 0, // 1-默认播放 0-默认暂停
  1325. i: this.opt.poster,
  1326. loaded: 'loadHandler'
  1327. };
  1328. } else {
  1329. flashvars = {
  1330. f: this.opt.currentSource,
  1331. c: 0,
  1332. p: 1,
  1333. loaded: 'loadHandler'
  1334. };
  1335. }
  1336. var params = { bgcolor: '#FFF', allowFullScreen: true, allowScriptAccess: 'always', wmode: 'transparent' };
  1337. this.flashId = this.opt.parentId + 'flashId';
  1338. window.CKobject.embedSWF(ckplayerSWF, this.opt.parentId, this.flashId, this.opt.width, this.opt.height, flashvars, params);
  1339. };
  1340. EZUIPlayer.prototype.initVideoEvent = function () {
  1341. var me = this;
  1342. var EVENT = {
  1343. 'loadstart': function (e) {
  1344. me.log('loadstart...当浏览器开始查找音频/视频时...');
  1345. me.emit('loadstart', e);
  1346. },
  1347. 'durationchange': function (e) {
  1348. me.log('durationchange...当音频/视频的时长已更改时...');
  1349. me.emit('durationchange', e);
  1350. },
  1351. 'loadedmetadata': function (e) {
  1352. me.log('loadedmetadata...当浏览器已加载音频/视频的元数据时...');
  1353. me.emit('loadedmetadata', e);
  1354. },
  1355. 'loadeddata': function (e) {
  1356. me.log('loadeddata...当浏览器已加载音频/视频的当前帧时...');
  1357. me.emit('loadeddata', e);
  1358. },
  1359. 'progress': function (e) {
  1360. me.log('progress...当浏览器正在下载音频/视频时...');
  1361. me.emit('progress', e);
  1362. },
  1363. 'canplay': function (e) {
  1364. me.log('canplay...当浏览器可以播放音频/视频时...');
  1365. me.emit('canplay', e);
  1366. },
  1367. 'canplaythrough': function (e) {
  1368. me.log('canplaythrough...当浏览器可在不因缓冲而停顿的情况下进行播放时...');
  1369. me.emit('canplaythrough', e);
  1370. },
  1371. 'abort': function (e) {
  1372. me.log('abort...当音频/视频的加载已放弃时...');
  1373. me.emit('abort', e);
  1374. },
  1375. 'emptied': function (e) {
  1376. me.log('emptied...当目前的播放列表为空时...');
  1377. me.emit('emptied', e);
  1378. },
  1379. 'ended': function (e) {
  1380. me.log('ended...当目前的播放列表已结束时...');
  1381. me.emit('ended', e);
  1382. },
  1383. 'pause': function (e) {
  1384. me.log('pause...当音频/视频已暂停时...');
  1385. me.emit('pause', e);
  1386. },
  1387. 'play': function (e) {
  1388. me.log('play...当音频/视频已开始或不再暂停时...');
  1389. me.emit('play', e);
  1390. },
  1391. 'playing': function (e) {
  1392. me.log('playing...当音频/视频在已因缓冲而暂停或停止后已就绪时...');
  1393. me.emit('playing', e);
  1394. },
  1395. 'ratechange': function (e) {
  1396. me.log('ratechange...当音频/视频的播放速度已更改时...');
  1397. me.emit('ratechange', e);
  1398. },
  1399. 'seeked': function (e) {
  1400. me.log('seeked...当用户已移动/跳跃到音频/视频中的新位置时...');
  1401. me.emit('seeked', e);
  1402. },
  1403. 'seeking': function (e) {
  1404. me.log('seeking...当用户开始移动/跳跃到音频/视频中的新位置时...');
  1405. me.emit('seeking', e);
  1406. },
  1407. 'stalled': function (e) {
  1408. me.log('stalled...当浏览器尝试获取媒体数据,但数据不可用时...');
  1409. me.emit('stalled', e);
  1410. },
  1411. 'suspend': function (e) {
  1412. me.log('suspend...当浏览器刻意不获取媒体数据时...');
  1413. me.emit('suspend', e);
  1414. if (me.opt.autoplay) {
  1415. me.video.play();
  1416. }
  1417. },
  1418. 'timeupdate': function (e) {
  1419. //me.log('timeupdate...当目前的播放位置已更改时...');
  1420. me.emit('timeupdate', e);
  1421. },
  1422. 'volumechange': function (e) {
  1423. me.log('volumechange...当音量已更改时...');
  1424. me.emit('volumechange', e);
  1425. },
  1426. 'waiting': function (e) {
  1427. me.log('waiting...当视频由于需要缓冲下一帧而停止...');
  1428. me.emit('waiting', e);
  1429. },
  1430. 'error': function (e) {
  1431. me.log('error...当在音频/视频加载期间发生错误时...');
  1432. me.emit('error', e);
  1433. }
  1434. };
  1435. for (var i in EVENT) {
  1436. this.video.addEventListener(i, EVENT[i], false);
  1437. }
  1438. ios11Hack(this.video);
  1439. };
  1440. EZUIPlayer.prototype.initJSmpeg = function (jsmpegUrl) {
  1441. this.canvasEle = document.createElement('canvas');
  1442. this.canvasEle.style.width = this.opt.width;
  1443. this.canvasEle.style.height = this.opt.height;
  1444. this.video.parentNode.replaceChild(this.canvasEle, this.video);
  1445. this.canvasEle.id = this.opt.parentId;
  1446. var player;
  1447. if (player && player.destroy) {
  1448. player.destroy();
  1449. }
  1450. player = new JSMpeg.Player(jsmpegUrl, { canvas: this.canvasEle });
  1451. this.JSmpeg = player;
  1452. };
  1453. EZUIPlayer.prototype.initflv = function () {
  1454. if (flvjs.isSupported()) {
  1455. var player = this.video;
  1456. var hasControls = player.getAttribute('controls');
  1457. if (!hasControls) {
  1458. player.setAttribute('controls', true);
  1459. }
  1460. var flvPlayer = flvjs.createPlayer({
  1461. type: 'flv',
  1462. url: this.opt.currentSource,
  1463. isLive: true,
  1464. }, {
  1465. enableStashBuffer: true,
  1466. stashInitialSize: 128,
  1467. enableWorker: true
  1468. });
  1469. flvPlayer.attachMediaElement(player);
  1470. flvPlayer.load();
  1471. flvPlayer.play();
  1472. } else {
  1473. this.log("浏览器不支持flv播放");
  1474. throw new Error('浏览器不支持flv播放');
  1475. return;
  1476. }
  1477. this.flv = flvPlayer;
  1478. };
  1479. EZUIPlayer.prototype.rePlay = function (playParams) {
  1480. this.loadingStart();
  1481. // _this.loadingSet(0,{text:'获取设备播放地址'})
  1482. var _this = this;
  1483. var getRealUrl = this.getRealUrl(playParams);
  1484. /**是否自动播放 */
  1485. if (isPromise(getRealUrl)) {
  1486. getRealUrl.then(function (data) {
  1487. _this.play(playParams);
  1488. })
  1489. .catch(function (err) {
  1490. console.log("播放错误", err)
  1491. });
  1492. }
  1493. }
  1494. EZUIPlayer.prototype.play = function (data) {
  1495. // debugger
  1496. //var index = params.index;
  1497. if (!!window['CKobject']) {
  1498. this.opt.autoplay = true;
  1499. this.initCKPlayer();
  1500. } else if (!!this.video) { // video播放 包含flv, hls
  1501. if (!!this.hls) { // hls开始播放依赖 this.hls
  1502. this.opt.autoplay = true;
  1503. this.hls.startLoad();
  1504. this.video.play();
  1505. } else if (!!this.JSmpeg) {
  1506. this.JSmpeg.play();
  1507. } else { // 其他开始播放使用原生video
  1508. this.opt.autoplay = true;
  1509. this.video.play();
  1510. }
  1511. } else if (!!this.jSPlugin) {
  1512. var playParams = this.playParams;
  1513. var audioId = 0
  1514. if(playParams && playParams.audioId){
  1515. audioId = playParams.audioId;
  1516. }else if(playParams && playParams.audioId === -1){
  1517. audioId = undefined;
  1518. }
  1519. if ( typeof data === 'string'){
  1520. playParams.url = data;
  1521. }else if(typeof data === 'object'){
  1522. playParams = Object.assign(playParams,data);
  1523. }
  1524. var getRealUrl = this.getRealUrl(playParams);
  1525. var _this = this;
  1526. getRealUrl.then(function () {
  1527. function getPlayParams(url) {
  1528. var websocketConnectUrl = url.split('?')[0].replace('/live', '').replace('/playback', '');
  1529. // console.log("playParams,",playParams,playParams.env.wsUrl)
  1530. // if(playParams && playParams.env && playParams.env.wsUrl){
  1531. // websocketConnectUrl= playParams.env.wsUrl;
  1532. // }
  1533. console.log("_this.opt.sources.", _this.opt.sources)
  1534. var websocketStreamingParam = (url.indexOf('/live') === -1 ? (url.indexOf('cloudplayback') !== -1 ? '/cloudplayback?' : '/playback?') : '/live?') + url.split('?')[1];
  1535. // 本地回放仅支持主码流 - 2019-11-05 修订
  1536. if (websocketStreamingParam.indexOf('/playback') !== -1) {
  1537. websocketStreamingParam = websocketStreamingParam.replace("stream=2", 'stream=1');
  1538. }
  1539. // 本地回放仅支持主码流
  1540. return { websocketConnectUrl: websocketConnectUrl, websocketStreamingParam: websocketStreamingParam }
  1541. }
  1542. _this.opt.sources.forEach(function (item, index) {
  1543. if (getQueryString('dev', item) || item.indexOf('ws') !== -1) {
  1544. _this.log("开始播放, 第" + (index + 1) + '路,' + '地址:' + item);
  1545. _this.loadingSet(index, { text: '准备播放...', color: '#fff' })
  1546. // 设置秘钥 - 如果地址中包含秘钥参数,播放前配置到JSPlugin对应实例中
  1547. var validateCode = getQueryString('checkCode', item);
  1548. if (validateCode) {
  1549. _this.log('设置秘钥,视频路数:' + (index + 1) + '验证码:' + validateCode)
  1550. _this.jSPlugin.JS_SetSecretKey(index, validateCode);
  1551. }
  1552. var playST = new Date().getTime();
  1553. var wsUrl = ''
  1554. var wsParams = ''
  1555. if (_this.playParams && _this.playParams.hasOwnProperty('userName') && _this.playParams.hasOwnProperty('password')) {
  1556. wsUrl = item.split('?')[0];
  1557. wsParams = {
  1558. sessionID: getQueryString('sessionID', item),
  1559. }
  1560. } else {
  1561. wsUrl = getPlayParams(item).websocketConnectUrl;
  1562. wsParams = {
  1563. playURL: getPlayParams(item).websocketStreamingParam
  1564. }
  1565. }
  1566. _this.jSPlugin.JS_Play(wsUrl, wsParams, index).then(function () {
  1567. _this.log('播放成功,当前播放第' + (index + 1) + '路');
  1568. _this.loadingSet(index, { text: '播放成功...' });
  1569. //单次播放日志上报
  1570. ezuikitDclog({
  1571. systemName: PERFORMANCE_EZUIKIT,
  1572. bn: 2,
  1573. browser: JSON.stringify(getBrowserInfo()),
  1574. duration: new Date().getTime() - playST,
  1575. rt: 200,
  1576. })
  1577. // 播放成功
  1578. ezuikitDclog({
  1579. systemName: PERFORMANCE_EZUIKIT,
  1580. bn: 99,
  1581. browser: JSON.stringify(getBrowserInfo()),
  1582. duration: new Date().getTime() - playStartTime,
  1583. rt: 200,
  1584. })
  1585. _this.loadingEnd(index);
  1586. // 默认开启声音
  1587. // 默认开启第一路声音
  1588. if (typeof(audioId) !== "undefined" && audioId === index) {
  1589. _this.log("默认开启第1路声音");
  1590. setTimeout(function () {
  1591. var openSoundRT = _this.jSPlugin.JS_OpenSound(0);
  1592. console.log("openSoundRT", openSoundRT)
  1593. openSoundRT.then(function (data) {
  1594. _this.log('开启声音成功', data)
  1595. })
  1596. .catch(function (err) {
  1597. _this.log('开启声音失败', 'error', err)
  1598. })
  1599. }, 100)
  1600. }
  1601. // 播放成功回调
  1602. if (playParams && playParams.handleSuccess) {
  1603. playParams.handleSuccess();
  1604. }
  1605. //
  1606. // 播放成功日志上报
  1607. var PlTp = 1;
  1608. if (playParams && playParams.url) {
  1609. if (playParams.url.indexOf('rec') !== -1) {
  1610. PlTp = 2;
  1611. }
  1612. }
  1613. dclog({
  1614. systemName: PLAY_MAIN,
  1615. playurl: encodeURIComponent(item),
  1616. Time: (new Date()).Format('yyyy-MM-dd hh:mm:ss.S'),
  1617. Enc: 0, // 0 不加密 1 加密
  1618. PlTp: PlTp, // 1 直播 2 回放
  1619. Via: 2, // 2 服务端取流
  1620. ErrCd: 0,
  1621. OpId: uuid(),
  1622. Cost: (new Date()).getTime() - _this.initTime, // 毫秒数
  1623. Serial: getQueryString('dev', item),
  1624. Channel: getQueryString('chn', item),
  1625. });
  1626. }, function (err) {
  1627. _this.log('播放失败' + JSON.stringify(err), 'error');
  1628. var errorInfo = JSON.parse(_this.errorCode).find(function (item) { return item.detailCode.substr(-4) == err.oError.errorCode });
  1629. ezuikitDclog({
  1630. systemName: PERFORMANCE_EZUIKIT,
  1631. bn: 2,
  1632. browser: JSON.stringify(getBrowserInfo()),
  1633. duration: new Date().getTime() - playStartTime,
  1634. rt: err.oError ? err.oError.errorCode : 500,
  1635. msg: errorInfo ? errorInfo.description : '播放过程其他错误'
  1636. })
  1637. var msg = errorInfo ? errorInfo.description : '播放过程其他错误';
  1638. _this.loadingSet(index, { text: msg, color: 'red' });
  1639. dclog({
  1640. systemName: PLAY_MAIN,
  1641. playurl: encodeURIComponent(item),
  1642. cost: -1,
  1643. ErrCd: (err && err.oError && err.oError.errorCode && (err.oError.errorCode + "").substr(-4)) || -1,
  1644. Via: 2,
  1645. OpId: uuid(),
  1646. Serial: getQueryString('dev', item),
  1647. Channel: getQueryString('chn', item),
  1648. });
  1649. if (playParams && playParams.handleError) {
  1650. var errorInfo = JSON.parse(_this.errorCode).find(function (item) { return item.detailCode.substr(-4) == err.oError.errorCode })
  1651. playParams.handleError({ retcode: err.oError.errorCode, msg: errorInfo ? errorInfo.description : '其他错误' });
  1652. }
  1653. })
  1654. } else {
  1655. if (isJSON(item) && JSON.parse(item).msg) {
  1656. _this.loadingSet(index, { text: JSON.parse(item).msg, color: 'red' })
  1657. }
  1658. }
  1659. })
  1660. })
  1661. }
  1662. };
  1663. EZUIPlayer.prototype.initDecoder = function (playParams) {
  1664. this.opt.id = playParams.id;
  1665. this.log("初始化解码器---开始");
  1666. var _this = this;
  1667. var initDecoderDurationST = new Date().getTime();
  1668. // DOM id
  1669. function initDecoder(resolve, reject) {
  1670. var jsPluginPath = playParams.decoderPath + '/js/jsPlugin-1.2.0.min.js';
  1671. /** 初始化解码器 */
  1672. addJs(jsPluginPath, function () {
  1673. _this.log("下载解码器完成,开始初始化");
  1674. /* decoder 属性配置 */
  1675. _this.jSPlugin = new JSPlugin({
  1676. szId: playParams.id,
  1677. // iType: 2,
  1678. // iMode: 0,
  1679. iWidth: playParams.width || 600,
  1680. iHeight: playParams.height || 400,
  1681. iMaxSplit: Math.ceil(Math.sqrt(playParams.url.split(",").length)),
  1682. iCurrentSplit: playParams.splitBasis || Math.ceil(Math.sqrt(playParams.url.split(",").length)),
  1683. szBasePath: playParams.decoderPath + '/js',
  1684. oStyle: {
  1685. border: "none",
  1686. background: "#000000"
  1687. }
  1688. });
  1689. _this.jSPlugin.JS_SetWindowControlCallback({
  1690. windowEventSelect: function (iWndIndex) { //插件选中窗口回调
  1691. iWind = iWndIndex;
  1692. },
  1693. pluginErrorHandler: function (iWndIndex, iErrorCode, oError) { //插件错误回调
  1694. console.log(iWndIndex, iErrorCode, oError);
  1695. if (playParams && playParams.handleError) {
  1696. playParams.handleError({ retcode: iErrorCode, msg: oError ? oError : '播放失败,请重试' });
  1697. if(playParams.url.indexOf("alarmId")!== -1) {
  1698. _this.loadingSetIcon(iWndIndex, 'retry');
  1699. _this.loadingSet(iWndIndex, { text: '播放结束' });
  1700. } else {
  1701. _this.loadingSetIcon(iWndIndex, 'retry');
  1702. _this.loadingSet(iWndIndex, { text: '播放失败,请重试' });
  1703. }
  1704. }
  1705. },
  1706. });
  1707. _this.jSPlugin.JS_SetOptions({
  1708. //bSupportSound: false //是否支持音频,默认支持
  1709. bSupporDoubleClickFull: typeof playParams.isSupporDoubleClickFull === 'undefined' ? true : playParams.isSupporDoubleClickFull, //是否双击窗口全屏,默认支持
  1710. //bOnlySupportMSE: true //只支持MSE
  1711. bOnlySupportJSDecoder: (typeof playParams.useMSE === 'undefined' || playParams.useMSE === false) ? true : false, //是否强制使用jsdecoder
  1712. }).then(function () {
  1713. console.log("JS_SetOptions");
  1714. });
  1715. // 注册全屏事件
  1716. window.onresize = function () {
  1717. _this.jSPlugin.JS_Resize(playParams.width || 600, playParams.height || 400);
  1718. }
  1719. _this.log("初始化解码器----完成");
  1720. // 执行一次初始化解码器服务请求上报
  1721. ezuikitDclog({
  1722. systemName: PERFORMANCE_EZUIKIT,
  1723. bn: 1,
  1724. browser: JSON.stringify(getBrowserInfo()),
  1725. duration: new Date().getTime() - initDecoderDurationST,
  1726. rt: 200,
  1727. })
  1728. resolve('200 OK')
  1729. });
  1730. /**
  1731. * 加载错误码
  1732. * 错误码维护平台 - omm管理系统
  1733. */
  1734. function success(data) {
  1735. if (data.code == 200) {
  1736. if (!window.localStorage) {
  1737. return false;
  1738. } else {
  1739. var storage = window.localStorage;
  1740. //写入a字段
  1741. storage["errorCode"] = JSON.stringify(data.data);
  1742. _this.errorCode = storage['errorCode'];
  1743. }
  1744. }
  1745. }
  1746. if (!window.localStorage) {
  1747. request(
  1748. playParams.decoderPath + "/js/errorCode.json",
  1749. "get",
  1750. {
  1751. language: 1,
  1752. time: new Date().getTime(),
  1753. appKey: '26810f3acd794862b608b6cfbc32a6b8',
  1754. },
  1755. '',
  1756. success
  1757. );
  1758. } else {
  1759. var storage = window.localStorage;
  1760. var errorCode = storage.errorCode;
  1761. if (!errorCode) {
  1762. request(
  1763. playParams.decoderPath + "/js/errorCode.json",
  1764. "get",
  1765. {
  1766. language: 1,
  1767. time: new Date().getTime(),
  1768. appKey: '26810f3acd794862b608b6cfbc32a6b8',
  1769. },
  1770. '',
  1771. success
  1772. );
  1773. } else {
  1774. _this.errorCode = storage['errorCode'];
  1775. }
  1776. }
  1777. }
  1778. var initDecoderPromise = new Promise(initDecoder);
  1779. return initDecoderPromise;
  1780. }
  1781. EZUIPlayer.prototype.stop = function (i, unDestory) {
  1782. // 执行停止
  1783. this.log("停止播放" + this.opt.currentSource);
  1784. this.opt.autoplay = false;
  1785. if (!!window['CKobject']) {
  1786. //CKobject.getObjectById(this.flashId).destroy();
  1787. this.video.src = ""
  1788. // this.video.remove();
  1789. } else if (!!this.video) {
  1790. if (!!this.hls) { // hls停止依赖this.hls
  1791. // 通过暂停停止播放
  1792. this.video.pause();
  1793. this.video.src = ""
  1794. // 停止取流
  1795. this.hls.stopLoad();
  1796. } else if (!!this.flv) {
  1797. this.flv.pause();
  1798. this.flv.unload();
  1799. this.flv.detachMediaElement();
  1800. this.flv.destroy();
  1801. this.flv = null;
  1802. } else if (!!this.JSmpeg) {
  1803. this.JSmpeg.stop();
  1804. // this.JSmpeg.destroy();
  1805. }
  1806. } else if (!!this.jSPlugin) {
  1807. var _this = this;
  1808. if (typeof i === "undefined") {
  1809. return this.jSPlugin.JS_Stop(0).then(function () {
  1810. _this.log("停止播放成功" + _this.opt.currentSource);
  1811. console.log("stop success");
  1812. // 额外销毁worker
  1813. // _this.jSPlugin.JS_DestroyWorker();
  1814. _this.loadingEnd(0);
  1815. //removeChild(0);
  1816. }, function () {
  1817. _this.log("停止播放失败" + _this.opt.currentSource);
  1818. console.log("stop failed");
  1819. });
  1820. } else {
  1821. return this.jSPlugin.JS_Stop(i).then(function () {
  1822. _this.log("第" + i + "路停止播放成功" + _this.opt.currentSource);
  1823. _this.loadingEnd(i);
  1824. console.log("stop success");
  1825. }, function () {
  1826. _this.log("第" + i + "路停止播放失败" + _this.opt.currentSource);
  1827. _this.loadingEnd(i);
  1828. console.log("stop failed");
  1829. });
  1830. // 额外销毁worker - 多窗口暂不销毁
  1831. // this.jSPlugin.JS_DestroyWorker();
  1832. //removeChild(i);
  1833. }
  1834. }
  1835. };
  1836. EZUIPlayer.prototype.destroy = function (i) {
  1837. _this.jSPlugin.JS_DestroyWorker();
  1838. }
  1839. // 获取OSD时间
  1840. // EZUIPlayer.prototype.getOSDTime = function (callback, iWind) {
  1841. // if (!!this.jSPlugin) {
  1842. // this.jSPlugin.JS_GetOSDTime(iWind || 0).then(function (iTime) {
  1843. // callback(iTime * 1000);
  1844. // }, function (err) {
  1845. // console.log("get OSD Time error", err);
  1846. // });
  1847. // } else {
  1848. // throw new Error("Method not support");
  1849. // }
  1850. // }
  1851. // 返回promise的getOSDTime方法
  1852. EZUIPlayer.prototype.getOSDTime = function (wNum) {
  1853. const _this = this;
  1854. if (!!this.jSPlugin) {
  1855. return _this.jSPlugin.JS_GetOSDTime(wNum || 0);
  1856. } else {
  1857. throw new Error("Method not support");
  1858. }
  1859. }
  1860. // 返回promise的getOSDTime方法
  1861. EZUIPlayer.prototype.getVersion = function (wNum) {
  1862. const _this = this;
  1863. if (!!this.jSPlugin) {
  1864. console.log(_this.jSPlugin.JS_GetSdkVersion());
  1865. } else {
  1866. throw new Error("Method not support");
  1867. }
  1868. }
  1869. // 开启声音
  1870. EZUIPlayer.prototype.openSound = function (iWind) {
  1871. if (!!this.jSPlugin) {
  1872. var openSoundRT = this.jSPlugin.JS_OpenSound(iWind || 0);
  1873. openSoundRT === 0 ? this.log('开启声音成功') : this.log('开启声音失败', 'error');
  1874. return openSoundRT;
  1875. } else {
  1876. throw new Error("Method not support");
  1877. }
  1878. }
  1879. // 全屏
  1880. EZUIPlayer.prototype.fullScreen = function () {
  1881. if (!!this.jSPlugin) {
  1882. return this.jSPlugin.JS_FullScreenDisplay(1);
  1883. } else {
  1884. throw new Error("Method not support");
  1885. }
  1886. }
  1887. // 关闭声音
  1888. EZUIPlayer.prototype.closeSound = function (iWind) {
  1889. if (!!this.jSPlugin) {
  1890. var closeSoundRT = this.jSPlugin.JS_CloseSound(iWind || 0);
  1891. closeSoundRT === 0 ? this.log('关闭声音成功') : this.log('关闭声音失败', 'error');
  1892. return closeSoundRT;
  1893. } else {
  1894. throw new Error("Method not support");
  1895. }
  1896. }
  1897. // 视频截图
  1898. EZUIPlayer.prototype.capturePicture = function (iWind, pictureName) {
  1899. if (!!this.jSPlugin) {
  1900. return this.jSPlugin.JS_CapturePicture(iWind, pictureName)
  1901. } else {
  1902. throw new Error("Method not support");
  1903. }
  1904. }
  1905. // 开始录像
  1906. EZUIPlayer.prototype.startSave = function (iWind, fileName) {
  1907. if (!!this.jSPlugin) {
  1908. this.log("开始录制录像");
  1909. return this.jSPlugin.JS_StartSave(iWind, fileName)
  1910. } else {
  1911. throw new Error("Method not support");
  1912. }
  1913. }
  1914. // 结束录像
  1915. EZUIPlayer.prototype.stopSave = function (iWind) {
  1916. if (!!this.jSPlugin) {
  1917. return this.jSPlugin.JS_StopSave(iWind);
  1918. this.log("结束录制录像");
  1919. } else {
  1920. throw new Error("Method not support");
  1921. }
  1922. }
  1923. EZUIPlayer.prototype.reSize = function (width, height) {
  1924. if (!!this.jSPlugin) {
  1925. return this.jSPlugin.JS_Resize(width, height);
  1926. } else {
  1927. throw new Error("Method not support");
  1928. }
  1929. }
  1930. EZUIPlayer.prototype.pause = function () {
  1931. this.opt.autoplay = false;
  1932. if (!!window['CKobject']) {
  1933. CKobject.getObjectById(this.flashId).videoPause();
  1934. } else if (!!this.video) {
  1935. if (!!this.JSmpeg) {
  1936. this.JSmpeg.pause();
  1937. } else {
  1938. this.video.pause();
  1939. }
  1940. } else if (!!this.jSPlugin) {
  1941. this.jSPlugin.JS_Pause(0).then(function () {
  1942. }, function () {
  1943. });
  1944. }
  1945. };
  1946. EZUIPlayer.prototype.load = function () {
  1947. if (!!window['CKobject']) {
  1948. // flash load
  1949. } else if (!!this.video) {
  1950. this.video.load();
  1951. }
  1952. };
  1953. // 开启电子放大
  1954. EZUIPlayer.prototype.enableZoom = function (iWind) {
  1955. if (!!this.jSPlugin) {
  1956. return this.jSPlugin.JS_EnableZoom(iWind || 0);
  1957. } else {
  1958. throw new Error("Method not support");
  1959. }
  1960. }
  1961. // 关闭电子放大
  1962. EZUIPlayer.prototype.closeZoom = function (iWind) {
  1963. if (!!this.jSPlugin) {
  1964. return this.jSPlugin.JS_DisableZoom(iWind || 0);
  1965. } else {
  1966. throw new Error("Method not support");
  1967. }
  1968. }
  1969. // iOS11手机HLS直播在m3u8响应时间过长后不继续请求的hack
  1970. function ios11Hack(video) { var isloadeddata = false; var isPlaying = false; var stalledCount = 0; video.addEventListener('loadeddata', function () { isloadeddata = true; }, false); video.addEventListener('stalled', function () { stalledCount++; if (!isPlaying) { if (stalledCount >= 2 && !isloadeddata) { video.load(); video.play(); isloadeddata = false; isPlaying = false; stalledCount = 0; } } }, false); video.addEventListener('playing', function () { isPlaying = true; }); }
  1971. function ltIE11() { var userAgent = navigator.userAgent; var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; if (isIE) { return true; } else { return false; } }
  1972. var EZUIKit = {
  1973. 'EZUIPlayer': EZUIPlayer,
  1974. };
  1975. // 兼容1.4 以下旧版本
  1976. // var EZUIPlayer = EZuikit.EZUIPlayer;
  1977. if (!noGlobal) {
  1978. window.EZUIKit = EZUIKit;
  1979. // 兼容1.4 以下旧版本
  1980. window.EZUIPlayer = EZUIPlayer;
  1981. }
  1982. return EZUIKit;
  1983. });