ezuikit.js 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614
  1. /**
  2. * jssdk 2.6
  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. function dclog(obj) {
  74. var domain = window.location.protocol + '//' + window.location.host;
  75. var logObj = {
  76. Ver: 'v.2.6.0',
  77. PlatAddr: domain,
  78. ExterVer: 'Ez.2.6.0',
  79. OpId: uuid(),
  80. CltType: 102,
  81. StartTime: (new Date()).Format('yyyy-MM-dd hh:mm:ss.S'), // 每个日志包含当前的时间
  82. OS: navigator.platform
  83. }
  84. for (var i in obj) {
  85. logObj[i] = obj[i];
  86. }
  87. var tempArray = [];
  88. for (var j in logObj) {
  89. tempArray.push(j + '=' + logObj[j]);
  90. }
  91. var params = '?' + tempArray.join('&');
  92. // 上报一次本地统计信息
  93. var img = new Image();
  94. img.src = logDomain + params;
  95. }
  96. // 日志上报-2019-09-10
  97. function ezuikitDclog(obj) {
  98. var domain = window.location.protocol + '//' + window.location.host;
  99. var logObj = {
  100. version: 'v.2.6.0',
  101. plate_addr: domain,
  102. st: new Date().getTime(), // 每个日志包含当前的时间
  103. }
  104. for (var i in obj) {
  105. logObj[i] = obj[i];
  106. }
  107. var tempArray = [];
  108. for (var j in logObj) {
  109. tempArray.push(j + '=' + logObj[j]);
  110. }
  111. var params = '?' + tempArray.join('&');
  112. // 上报一次本地统计信息
  113. var img = new Image();
  114. img.src = logDomain + params;
  115. }
  116. // 上报一次本地信息
  117. dclog({
  118. systemName: LOCALINFO
  119. });
  120. // 上报一次本地信息-新
  121. ezuikitDclog({
  122. systemName: LOCALINFO_EZUIKIT,
  123. os: navigator.platform,
  124. browser: JSON.stringify(getBrowserInfo())
  125. })
  126. var RTMP_REG = /^rtmp/;
  127. var HLS_REG = /\.m3u8/;
  128. // 获取元素样式
  129. function getStyle(el) {
  130. return window.getComputedStyle
  131. ? window.getComputedStyle(el, null)
  132. : el.currentStyle;
  133. }
  134. // 加载js
  135. function addJs(filepath, callback) {
  136. var oJs = document.createElement("script");
  137. oJs.setAttribute("src", filepath);
  138. oJs.onload = callback;
  139. document.getElementsByTagName("head")[0].appendChild(oJs);
  140. }
  141. // 通用请求方法
  142. function request(url, method, params, header, success, error) {
  143. var _url = url;
  144. var http_request = new XMLHttpRequest();
  145. http_request.onreadystatechange = function () {
  146. if (http_request.readyState == 4) {
  147. if (http_request.status == 200) {
  148. var _data = JSON.parse(http_request.responseText);
  149. success(_data);
  150. }
  151. }
  152. };
  153. http_request.open(method, _url, true);
  154. // http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  155. var data = new FormData();
  156. for (i in params) {
  157. data.append(i, params[i]);
  158. }
  159. http_request.send(data);
  160. };
  161. /** 获取url参数 */
  162. function getQueryString(name, url) {var r = new RegExp("(\\?|#|&)" + name + "=(.*?)(#|&|$)");var m = (url || location.href).match(r);return decodeURIComponent(m ? m[2] : '');}
  163. /** 判断是否为promise对象 */
  164. function isPromise(obj) { return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; }
  165. /** 生成uuid */
  166. 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;}
  167. /**获取浏览器名称,版本 */
  168. 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;}
  169. /** 是否为JSON格式字符串 */
  170. 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!')}
  171. var EZUIPlayer = function (playParams) {
  172. if (!isModernBrowser) {
  173. throw new Error('不支持ie8等低版本浏览器');
  174. return;
  175. }
  176. /**定义播放配置项 */
  177. this.opt = {};
  178. this.opt.sources = [];
  179. this.handlers = {};
  180. // 修订 - 支持JS Decoder 允许非字符串配置项
  181. if (typeof playParams === 'object' && playParams.hasOwnProperty('decoderPath')) {
  182. /* 校验播放器配置参数合法性 */
  183. var oS=document.createElement('style');
  184. document.getElementsByTagName("head")[0].appendChild(oS);
  185. oS.innerHTML= '.draw-window {border: none!important}';
  186. // 解码器路径
  187. if (typeof playParams.decoderPath !== 'string' || typeof playParams.decoderPath === 'undefined') {
  188. throw new Error('EZUIDecoder requires the path of decoder');
  189. return;
  190. }
  191. // Id
  192. if (typeof playParams.id !== 'string' || typeof playParams.id === 'undefined') {
  193. throw new Error('EZUIDecoder requires parameter id');
  194. return;
  195. }
  196. if (typeof playParams.url !== 'string' || typeof playParams.url === 'undefined') {
  197. throw new Error('EZUIDecoder requires parameter url');
  198. return;
  199. }
  200. // 状态提示
  201. this.loadingStart = function(){
  202. var oS=document.createElement('style');
  203. document.getElementsByTagName("head")[0].appendChild(oS);
  204. 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;}';
  205. /**DOM 操作方法 */
  206. function insertAfter( newElement, targetElement ){
  207. var parent = targetElement.parentNode;
  208. if( parent.lastChild == targetElement ){
  209. parent.appendChild( newElement );
  210. }else{
  211. parent.insertBefore( newElement, targetElement.nextSibling );
  212. }
  213. }
  214. if(playParams && playParams.id){
  215. var domId = playParams.id;
  216. var domElement = document.getElementById(domId);
  217. var windowWidth = domElement.offsetWidth;
  218. var windowHeight = domElement.offsetHeight || playParams.height || 400;
  219. var offsetTop = domElement.offsetTop;
  220. var offsetLeft = domElement.offsetLeft;
  221. // 先执行清空loading
  222. if(document.getElementById('loading-id-0')){
  223. document.getElementById('loading-id-0').parentNode.removeChild(document.getElementById('loading-id-0'))
  224. }
  225. var loadingContainerDOM = document.createElement('div');
  226. loadingContainerDOM.setAttribute('id','loading-id-0');
  227. var style = 'position:absolute;outline:none;'
  228. style += 'width: 0px;'
  229. style += 'height: 0px;'
  230. style += 'top:' + offsetTop + 'px;'
  231. style += 'left:' + offsetLeft + 'px;'
  232. loadingContainerDOM.setAttribute('style',style);
  233. var loadingContainer = document.getElementById("loading-id-0");
  234. loadingContainerDOM.style.height = windowHeight;
  235. loadingContainerDOM.setAttribute('class','loading-container');
  236. // loadingContainerDOM.innerHTML= loading;
  237. insertAfter( loadingContainerDOM,domElement );
  238. var splitBasis = playParams.splitBasis || 1;
  239. var windowLength = playParams.url.split(",").length;
  240. for(var i=0; i< windowLength; i++){
  241. var loadingContainer = document.createElement('div');
  242. var loadingStatusDOM = document.createElement('div');
  243. loadingContainer.setAttribute('class','loading-item');
  244. loadingContainer.setAttribute('id','loading-item-' + i);
  245. //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');
  246. 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;';
  247. style += ('left:' + calLoadingPostion(windowHeight,windowWidth,splitBasis,i).left + 'px;');
  248. style += ('top:' + calLoadingPostion(windowHeight,windowWidth,splitBasis,i).top + 'px;');
  249. loadingContainer.setAttribute('style',style);
  250. function calLoadingPostion(windowHeight,windowWidth,splitBasis,i){
  251. var top = parseInt(i / splitBasis,10)*(windowHeight/splitBasis);
  252. var left = (i % splitBasis) * (windowWidth/splitBasis);
  253. return {
  254. top:top,
  255. left:left
  256. }
  257. }
  258. var loadingDOM = document.createElement('div');
  259. loadingStatusDOM.innerHTML="";
  260. loadingStatusDOM.style.color="#fff";
  261. loadingDOM.setAttribute('class','loading');
  262. 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>';
  263. if(playParams.loading && playParams.loading.svg){
  264. loading = playParams.loading.svg;
  265. }
  266. loadingDOM.innerHTML = loading;
  267. loadingContainer.appendChild(loadingDOM);
  268. // loadingContainer.appendChild(loading);
  269. loadingContainer.appendChild(loadingStatusDOM);
  270. loadingContainerDOM.appendChild(loadingContainer)
  271. }
  272. }
  273. }
  274. this.loadingSet = function(index,opt){
  275. var loadingContainer = document.getElementById('loading-id-0');
  276. if(document.getElementById('loading-item-' + index)){
  277. var textElement = document.getElementById('loading-item-' + index).childNodes[1];
  278. textElement.innerHTML = opt.text;
  279. if(opt.color){
  280. textElement.style.color = opt.color;
  281. }
  282. }
  283. }
  284. this.loadingEnd = function(index){
  285. var loadingItemContainerDOM = document.getElementById('loading-item-' + index);
  286. if(loadingItemContainerDOM){
  287. loadingItemContainerDOM.parentNode.removeChild(loadingItemContainerDOM);
  288. var loadingContainerDOM = document.getElementById('loading-id-0');
  289. if(loadingContainerDOM && loadingContainerDOM.children.length===0){
  290. loadingContainerDOM.parentNode.removeChild(loadingContainerDOM);
  291. }
  292. }
  293. }
  294. // 将播放地址配置在实例 opt 属性中
  295. this.opt.sources.push(playParams.url);
  296. // JSDecoder 只有一个播放地址
  297. this.opt.currentSource = this.opt.sources[0];
  298. /* 获取解码器用户配置项 - 开始 */
  299. /**
  300. * 调试模式配置
  301. * 可通过dev属性指定API服务域名
  302. */
  303. var domain = "https://open.ys7.com";
  304. if (playParams.env) {
  305. var environmentParams = playParams.env;
  306. domain = environmentParams.domain;
  307. }
  308. /** 创建jSPlugin 对象 */
  309. this.jSPlugin = {};
  310. var _this = this;
  311. /** 根据播放参数获取真实播放地址 */
  312. this.loadingStart();
  313. playStartTime = new Date().getTime();
  314. var getRealUrl = this.getRealUrl(playParams);
  315. /**是否自动播放 */
  316. if (isPromise(getRealUrl)) {
  317. getRealUrl.then(function (data) {
  318. var initDecoder = _this.initDecoder(playParams);
  319. // 初始化播放器
  320. _this.loadingSet(0,{text:'初始化播放器...'});
  321. if (isPromise(initDecoder) && (playParams.autoplay !== false)) {
  322. initDecoder.then(function (data) {
  323. _this.loadingSet(0,{text:'初始化完成'});
  324. _this.play({ handleError: playParams.handleError, handleSuccess: playParams.handleSuccess },playParams);
  325. })
  326. }
  327. })
  328. .catch(function (err) {
  329. var initDecoder = _this.initDecoder(playParams);
  330. if (isPromise(initDecoder) && (playParams.autoplay !== false)) {
  331. initDecoder.then(function () {
  332. // _this.play({ handleError: playParams.handleError });
  333. })
  334. }
  335. });
  336. }
  337. } else {
  338. var elementID = '';
  339. if (typeof playParams === 'string') { //缩写模式 new EZUIPlayer('myplayer')
  340. elementID = playParams;
  341. } else if (typeof playParams === 'object') { //标准模式 new EZUIPlayer({id: 'myplayer'})
  342. elementID = playParams.id;
  343. }
  344. this.videoId = elementID;
  345. this.video = document.getElementById(elementID);
  346. if (!this.video) {
  347. throw new Error('EZUIPlayer requires parameter videoId');
  348. }
  349. var sources = this.video.getElementsByTagName('source');
  350. // 转为数组对象,不受removeChild影响
  351. sources = Array.prototype.slice.call(sources, 0);
  352. if (this.video.src) {
  353. // 移动端删除rtmp地址
  354. if (isMobile && RTMP_REG.test(this.video.src)) {
  355. this.video.removeAttribute('src');
  356. this.video.load();
  357. } else {
  358. this.opt.sources.push(this.video.src);
  359. }
  360. }
  361. var l = sources.length;
  362. if (l > 0) {
  363. for (var i = 0; i < l; i++) {
  364. // 移动端删除rtmp地址
  365. if (isMobile && RTMP_REG.test(sources[i].src)) {
  366. this.video.removeChild(sources[i]);
  367. } else {
  368. this.opt.sources.push(sources[i].src);
  369. }
  370. }
  371. }
  372. if (this.opt.sources.length < 1) {
  373. throw new Error('no source found in video tag.');
  374. }
  375. this.opt.cur = 0;
  376. this.opt.poster = this.video.poster;
  377. var videoStyle = getStyle(this.video);
  378. var width = this.video.width;
  379. var height = this.video.height;
  380. if (width) {
  381. this.opt.width = width;
  382. if (height) {
  383. this.opt.height = height;
  384. } else {
  385. this.opt.height = 'auto';
  386. }
  387. this.log('video width:' + this.opt.width + ' height:' + this.opt.height);
  388. } else {
  389. this.opt.width = videoStyle.width;
  390. this.opt.height = videoStyle.height;
  391. this.log('videoStyle.width:' + videoStyle.width + ' wideoStyle.height:' + videoStyle.height);
  392. }
  393. this.opt.parentId = elementID;
  394. this.opt.autoplay = this.video.autoplay ? true : false;
  395. this.log('autoplay:' + this.video.autoplay);
  396. this.opt.currentSource = this.opt.sources[this.opt.cur];
  397. this.getRealUrl(playParams);
  398. }
  399. /* 创建播放,错误,停止事件钩子,上报用户行为 */
  400. this.handlers = {};
  401. this.initTime = (new Date()).getTime();
  402. this.on('play', function () {
  403. // 上报播放成功信息
  404. dclog({
  405. systemName: PLAY_MAIN,
  406. playurl: this.opt.currentSource,
  407. Time: (new Date()).Format('yyyy-MM-dd hh:mm:ss.S'),
  408. Enc: 0, // 0 不加密 1 加密
  409. PlTp: 1, // 1 直播 2 回放
  410. Via: 2, // 2 服务端取流
  411. ErrCd: 0,
  412. OpId: uuid(),
  413. Cost: (new Date()).getTime() - this.initTime // 毫秒数
  414. });
  415. });
  416. this.retry = 2;
  417. this.on('error', function () {
  418. dclog({
  419. systemName: PLAY_MAIN,
  420. playurl: this.opt.currentSource,
  421. cost: -1,
  422. ErrCd: -1,
  423. OpId: uuid(),
  424. });
  425. });
  426. };
  427. // 事件监听
  428. EZUIPlayer.prototype.on = function (eventName, callback) {
  429. if (typeof eventName !== 'string' || typeof callback !== 'function') {
  430. return;
  431. }
  432. if (typeof this.handlers[eventName] === 'undefined') {
  433. this.handlers[eventName] = [];
  434. }
  435. this.handlers[eventName].push(callback);
  436. };
  437. // 事件触发
  438. EZUIPlayer.prototype.emit = function () {
  439. if (this.handlers[arguments[0]] instanceof Array) {
  440. var handlers = this.handlers[arguments[0]];
  441. var l = handlers.length;
  442. for (var i = 0; i < l; i++) {
  443. handlers[i].apply(this, Array.prototype.slice.call(arguments, 1));
  444. }
  445. }
  446. };
  447. // 日志
  448. EZUIPlayer.prototype.log = function (msg, className) {
  449. this.emit('log', msg, className);
  450. };
  451. EZUIPlayer.prototype.getRealUrl = function (playParams) {
  452. var _this = this;
  453. var apiDomain = 'https://open.ys7.com';
  454. if (playParams && playParams.env) {
  455. apiDomain = playParams.env.domain;
  456. }
  457. /** jsDecoder 获取真实地址 -- 开始 */
  458. if (playParams && playParams.hasOwnProperty('decoderPath')) {
  459. // api 获取真实地址开始时间
  460. var getRealUrlDurationST = new Date().getTime();
  461. var getRealUrlPromise = function (resolve, reject, ezopenURL) {
  462. var realUrl = '';
  463. if (!/^ezopen:\/\//.test(ezopenURL)) { // JSDecoder ws协议播放
  464. resolve(ezopenURL);
  465. } else {
  466. var getPlayTokenST = new Date().getTime();
  467. var nodeUrl = apiDomain + "/jssdk/ezopen/getStreamToken?accessToken=" + playParams.accessToken + '&num=10&type=' + (playParams.url.indexOf('live') !== -1 ? 'live' : 'playback');
  468. var nodeSuccess = function (data) {
  469. if (data.retcode === 0) {
  470. realUrl = realUrl + data.data.params + '&ssn=' + data.data.tokens[0];
  471. // _this.opt.currentSource = realUrl;
  472. ezuikitDclog({
  473. systemName: PERFORMANCE_EZUIKIT,
  474. bn: 3,
  475. browser: JSON.stringify(getBrowserInfo()),
  476. duration: new Date().getTime() - getPlayTokenST,
  477. rt: 200,
  478. })
  479. resolve(realUrl);
  480. } else {
  481. // 将错误信息捕获到用户自定义错误回调中
  482. if (playParams && playParams.handleError) {
  483. playParams.handleError(data);
  484. }
  485. // 错误信息显示在状态中
  486. if(data.msg){
  487. _this.loadingSet(0,{text:data.msg,color:'red'});
  488. }
  489. ezuikitDclog({
  490. systemName: PERFORMANCE_EZUIKIT,
  491. bn: 3,
  492. browser: JSON.stringify(getBrowserInfo()),
  493. duration: new Date().getTime() - getPlayTokenST,
  494. rt: data.retcode,
  495. msg: data.msg,
  496. })
  497. resolve(JSON.stringify(data));
  498. throw new Error('获取播放token失败');
  499. }
  500. }
  501. var nodeError = function (error) {
  502. // 将错误信息捕获到用户自定义错误回调中
  503. if (playParams && playParams.handleError) {
  504. playParams.handleError(error);
  505. }
  506. ezuikitDclog({
  507. systemName: PERFORMANCE_EZUIKIT,
  508. bn: 3,
  509. browser: JSON.stringify(getBrowserInfo()),
  510. duration: new Date().getTime() - getPlayTokenST,
  511. rt: 500,
  512. msg: '获取取流token网络错误',
  513. })
  514. resolve(JSON.stringify(error))
  515. throw new Error('获取播放token失败', 'error');
  516. }
  517. // 向API请求真实地址
  518. var apiUrl = apiDomain + "/api/lapp/live/url/ezopen";
  519. var apiSuccess = function (data) {
  520. if (data.code == 200 || data.retcode == 0) {
  521. realUrl += data.data;
  522. /**参数容错处理 start*/
  523. if (data.data.indexOf('playback') !== -1) { //回放
  524. // 兼容各种时间格式
  525. if (!getQueryString('begin', data.data)) {
  526. var defaultDate = new Date();
  527. realUrl = realUrl + '&begin=' + defaultDate.Format('yyyyMMdd') + 'T000000Z';
  528. } else {
  529. realUrl = realUrl.replace('&begin=' + getQueryString('begin', data.data), '&begin=' + formatRecTime(getQueryString('begin', data.data), '000000'))
  530. }
  531. if (!getQueryString('end', data.data)) {
  532. var defaultDate = new Date();
  533. realUrl = realUrl + '&end=' + defaultDate.Format('yyyyMMdd') + 'T235959Z';
  534. } else {
  535. realUrl = realUrl.replace('&end=' + getQueryString('end', data.data), '&end=' + formatRecTime(getQueryString('end', data.data), '235959'))
  536. }
  537. // api错误处理
  538. if (!getQueryString('stream', data.data)) {
  539. realUrl = realUrl.replace('stream', '&stream');
  540. }
  541. if(playParams.url.indexOf('.cloud')!== -1){
  542. // 调用回放API接口获取回放片段 - start
  543. var recBegin = reRormatRecTime(getQueryString('begin',realUrl));
  544. var recEnd = reRormatRecTime(getQueryString('end',realUrl));
  545. var deviceSerial = getQueryString('serial',realUrl)
  546. var channelNo = getQueryString('chn',realUrl);
  547. var recSliceUrl = apiDomain + "/api/lapp/video/by/time";
  548. var recSliceParams = {
  549. accessToken: playParams.accessToken,
  550. recType: 1,
  551. deviceSerial:deviceSerial,
  552. channelNo:channelNo,
  553. startTime:recBegin,
  554. endTime:recEnd
  555. }
  556. function recAPISuccess(data){
  557. if(data.code == 200 ) {
  558. var recSliceArr = [];
  559. if(data.data && data.data.length>0){
  560. recSliceArr = recSliceArrFun(data.data);
  561. var recSliceArrJSON = JSON.stringify(recSliceArr).replace('\\','');
  562. realUrl += ('&recSlice=' + recSliceArrJSON.replace('\\',''));
  563. request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError);
  564. } else {
  565. _this.log('未找到录像片段', 'error');
  566. _this.loadingSet(0,{text:'获取设备播放地址'})
  567. resolve(JSON.stringify({code:-1,msg:"未找到录像片段"}))
  568. // reject('未找到录像片段');
  569. }
  570. } else {
  571. _this.log(data.msg, 'error');
  572. _this.loadingSet(0,{text:'获取设备播放地址'});
  573. resolve(JSON.stringify({code:-1,msg:"未找到录像片段"}))
  574. //reject('未找到录像片段');
  575. }
  576. function recSliceArrFun(data){
  577. var downloadPathArr = [];
  578. var currentDP = downloadPathArr.length
  579. data.forEach(function(item,index){
  580. if(downloadPathArr.length == 0 || (item.downloadPath !== downloadPathArr[downloadPathArr.length-1].downloadPath)){
  581. downloadPathArr.push({
  582. downloadPath: item.downloadPath,
  583. ownerId: item.ownerId,
  584. iStorageVersion: item.iStorageVersion,
  585. videoType: item.videoType,
  586. iPlaySpeed: 0,
  587. startTime: item.startTime,
  588. endTime: item.endTime
  589. })
  590. }else {
  591. downloadPathArr[downloadPathArr.length-1].endTime = item.endTime;
  592. }
  593. })
  594. return downloadPathArr;
  595. }
  596. }
  597. function recAPIError(err){
  598. console.log("获取回放片段错误")
  599. }
  600. request(recSliceUrl, 'POST', recSliceParams, '', recAPISuccess, recAPIError);
  601. } else {// 本地回放
  602. request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError);
  603. }
  604. } else {
  605. // 预览直接获取回放片段
  606. request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError);
  607. }
  608. getPlayTokenST = new Date().getTime();
  609. // 执行一次API服务请求上报
  610. var getRealUrlDurationET = new Date().getTime();
  611. ezuikitDclog({
  612. systemName: PERFORMANCE_EZUIKIT,
  613. bn: 0,
  614. browser: JSON.stringify(getBrowserInfo()),
  615. duration: getRealUrlDurationET - getRealUrlDurationST,
  616. rt: 200,
  617. })
  618. } else {
  619. // 将错误信息捕获到用户自定义错误回调中
  620. if (playParams && playParams.handleError) {
  621. playParams.handleError(data);
  622. }
  623. // 执行一次API服务请求服务错误上报
  624. var getRealUrlDurationET = new Date().getTime();
  625. ezuikitDclog({
  626. systemName: PERFORMANCE_EZUIKIT,
  627. bn: 0,
  628. browser: JSON.stringify(getBrowserInfo()),
  629. duration: getRealUrlDurationET - getRealUrlDurationST,
  630. rt: data.code || 500,
  631. msg: data.msg || '未知服务错误'
  632. })
  633. resolve(JSON.stringify(data), 'error')
  634. //throw new Error('获取播放设备信息失败');
  635. }
  636. /**参数容错处理 end*/
  637. }
  638. var apiError = function (error) {
  639. // 将错误信息捕获到用户自定义错误回调中
  640. if (playParams && playParams.handleError) {
  641. playParams.handleError(error);
  642. }
  643. var getRealUrlDurationET = new Date().getTime();
  644. ezuikitDclog({
  645. systemName: PERFORMANCE_EZUIKIT,
  646. bn: 0,
  647. browser: JSON.stringify(getBrowserInfo()),
  648. duration: getRealUrlDurationET - getRealUrlDurationST,
  649. rt: 500,
  650. msg: data.msg || '网络错误'
  651. })
  652. resolve(JSON.stringify(error))
  653. //throw new Error('获取播放设备信息失败');
  654. }
  655. var isHttp = 'false';
  656. if (playParams && playParams.env && playParams.env.domain) {
  657. isHttp = playParams.env.domain.indexOf('https') !== -1 ? 'false' : 'true';
  658. } else {
  659. isHttp = window.location.href.indexOf('https') !== -1 ? 'false' : 'true';
  660. }
  661. var apiParams = {
  662. ezopen: ezopenURL,
  663. userAgent: window.navigator.userAgent,
  664. isFlv: false,
  665. addressTypes: null,
  666. isHttp: isHttp,
  667. accessToken: playParams.accessToken,
  668. }
  669. request(apiUrl, 'POST', apiParams, '', apiSuccess, apiError);
  670. }
  671. }
  672. var urlList = playParams.url.split(',')
  673. var promiseTaskList = [];
  674. var promiseTaskFun = function(ezopenURL) {
  675. return new Promise(function(resolve, reject){return getRealUrlPromise(resolve, reject, ezopenURL)})
  676. };
  677. urlList.map(function (item, index) {
  678. _this.loadingSet(index,{text:'获取设备播放地址'})
  679. promiseTaskList.push(promiseTaskFun(item));
  680. });
  681. var getRealUrlPromiseObj = Promise.all(promiseTaskList)
  682. .then(function (result) {
  683. // 获取真实地址成功后,赋值到opt属性中
  684. _this.opt.sources = result;
  685. _this.opt.currentSource = result[0];
  686. result.forEach(function(item,index){
  687. _this.loadingSet(index,{text:'获取播放地址成功'})
  688. })
  689. })
  690. .catch(function (err) {
  691. _this.log("获取真实地址错误" + JSON.stringify(err), 'error')
  692. })
  693. return getRealUrlPromiseObj;
  694. } else {
  695. if (!this.opt.currentSource) {
  696. this.log('未找到合适的播放URL', 'error');
  697. return;
  698. }
  699. var me = this;
  700. // 如果不是ezopen打头的,走原来的播放模式
  701. if (!/^ezopen:\/\//.test(this.opt.currentSource)) {
  702. this.tryPlay(this.opt.currentSource);
  703. } else {
  704. // 如果是ezopen协议地址,先校验一下地址的合法性
  705. if (!/^ezopen:\/\//.test(this.opt.currentSource)) {
  706. throw new Error('EZOPEN地址必须要以ezopen://开头');
  707. return;
  708. } else if (this.opt.currentSource.indexOf('.com/') === -1) {
  709. throw new Error('EZOPEN地址格式不正确');
  710. return;
  711. } else if (!/[a-z\d]{32}(\.hd)?\.live/.test(this.opt.currentSource)) {
  712. throw new Error('EZOPEN地址格式uuid格式不正确');
  713. return;
  714. } else if (/(.*.hls.*|.*.m3u8.*|.*.wss.*|.*.flv.*|.*.rtmp.*){2,}/.test(this.opt.currentSource)) {
  715. throw new Error('EZOPEN地址多于两个播放协议');
  716. return;
  717. } else if (this.opt.currentSource.search(/(.hls|.m3u8|.wss|.flv|.rtmp)/) !== -1 && !/.live(.hls|.m3u8|.wss|.flv|.rtmp)/.test(this.opt.currentSource)) {
  718. throw new Error('请指定正确的播放协议');
  719. return;
  720. } else if (this.opt.currentSource.search(/(.hls|.m3u8|.wss|.flv|.rtmp)/) === -1 && !/[a-z\d]{32}(\.hd)?\.live$/.test(this.opt.currentSource)) {
  721. throw new Error('EZOPEN地址结尾不正确');
  722. return;
  723. } else {
  724. /* 获取播放地址 - 开始 */
  725. var that = this;
  726. addJs(flv_js, function () {
  727. var para = {
  728. "ezopen": that.opt.currentSource,
  729. "userAgent": window.navigator.userAgent,
  730. "isFlv": flvjs && flvjs.isSupported() ? flvjs.isSupported() : false,
  731. "addressTypes": "HLS,RTMP,WS,FLV",
  732. "isHttp": window.location.protocol.indexOf('s') > 0 ? false : true,
  733. };
  734. dclog({
  735. "ezopen": that.opt.currentSource,
  736. "userAgent": window.navigator.userAgent,
  737. "isFlv": flvjs && flvjs.isSupported() ? flvjs.isSupported() : false,
  738. "addressTypes": "HLS,RTMP,WS,FLV",
  739. "isHttp": window.location.protocol.indexOf('s') > 0 ? false : true,
  740. 'systemName': 'EZOPEN',
  741. });
  742. that.log('---------------------------------------');
  743. that.log('入参(ezopen)是: ' + para.ezopen);
  744. that.log('---------------------------------------');
  745. that.log('入参(userAgent)是: ' + para.userAgent);
  746. that.log('---------------------------------------');
  747. that.log('入参(isFlv)是: ' + para.isFlv);
  748. that.log('---------------------------------------');
  749. that.log('入参(addressTypes)是: ' + para.addressTypes);
  750. that.log('---------------------------------------');
  751. that.log('入参(isHttp)是: ' + para.isHttp);
  752. that.log('---------------------------------------');
  753. var apiUrl = apiDomain + "/api/lapp/live/url/ezopen";
  754. var apiSuccess = function (data) {
  755. if (data.code == 200) {
  756. that.log('播放地址是: ' + data.data);
  757. that.video.src = data.data;
  758. that.video.load();
  759. that.tryPlay(data.data);
  760. } else {
  761. that.log('data: ' + JSON.stringify(data));
  762. throw new Error(data.msg);
  763. return;
  764. }
  765. }
  766. var apiError = function (error) {
  767. console.log("getdecoder url from api error", error);
  768. }
  769. request(apiUrl, 'POST', para, '', apiSuccess, apiError);
  770. });
  771. } /* 获取播放地址 - 结束 */
  772. }
  773. }
  774. // 格式化回放时间
  775. function formatRecTime(time, defaultTime) {
  776. // 用户格式 无需更改 => 20182626T000000Z
  777. // return time
  778. // 用户格式需要更改
  779. //用户时间长度为 14 20181226000000 =》 20181226000000
  780. // 用户长度为12 201812260000 =》 201812260000 + defaultTime后面2位
  781. // 用户长度为10 2018122600 =》 201812260000 + defaultTime后面4位
  782. // 用户长度为8 20181226 =》 201812260000 + defaultTime后面6位
  783. // 结果 20181226000000 14位
  784. // 插入 TZ
  785. var reg = /^[0-9]{8}T[0-9]{6}Z$/;
  786. if (reg.test(time)) { // 用户格式 无需更改 => 20182626T000000Z
  787. return time;
  788. } else if (/[0-9]{8,14}/.test(time)) {
  789. var start = 6 - (14 - time.length);
  790. var end = defaultTime.length;
  791. var standardTime = time + defaultTime.substring(start, end);
  792. return standardTime.slice(0, 8) + 'T' + standardTime.slice(8) + 'Z';
  793. } else {
  794. throw new Error('回放时间格式有误,请确认');
  795. }
  796. }
  797. function reRormatRecTime(time){
  798. var year = time.slice(0,4);
  799. var month = time.slice(4,6);
  800. var day = time.slice(6,8);
  801. var hour = time.slice(9,11);
  802. var minute = time.slice(11,13);
  803. var second = time.slice(13,15);
  804. var date = year + '-' + month + '-' + day + ' ' + hour + ':' + minute +':' + second;
  805. return new Date(date.replace(/-/g,'/')).getTime();
  806. }
  807. };
  808. // 尝试播放
  809. EZUIPlayer.prototype.tryPlay = function (playParams) {
  810. this.log("开始尝试播放,播放配置参数为:");
  811. this.log(playParams);
  812. var _this = this;
  813. // JSDecoder 播放
  814. if (playParams && typeof playParams === 'object' && playParams.decoderPath) {
  815. /** 初始化Decoder */
  816. // this.initDecoder(playParams);
  817. // 自动播放
  818. // if(playParams.autoplay){
  819. // console.log('配置了自动播放');
  820. // setTimeout(function(){
  821. // _this.play();
  822. // },2000)
  823. // }
  824. } else {
  825. this.opt.currentSource = playParams;
  826. var me = this;
  827. // 如果是HLS地址
  828. if (/\.m3u8/.test(playParams)) {
  829. // 如果是手机浏览器环境,或者原生支持HLS播放的,直接使用video标签播放
  830. // 否则尝试使用hls.js播放,
  831. // 最后使用flash
  832. if (isMobile || isNativeSupportHls) {
  833. this.log('使用原生video');
  834. this.video.style.heght = this.opt.height = Number(this.opt.width.replace(/px$/g, '')) * 9 / 16 + 'px';
  835. this.initVideoEvent();
  836. } else {
  837. var isPlayUrlHttps = playParams.indexOf('https') !== -1;
  838. if (isHttps && !isPlayUrlHttps) { //https网站,http视频源安全问题需要flash播放
  839. addJs(ckplayerJS, function () {
  840. me.initCKPlayer();
  841. });
  842. } else {
  843. addJs(hlsJS, function () {
  844. isSupportHls = Hls.isSupported();
  845. if (isSupportHls) {
  846. me.log('使用hls.js');
  847. me.initHLS(playParams);
  848. } else {
  849. useFlash = true;
  850. me.log('2 使用flash');
  851. addJs(ckplayerJS, function () {
  852. me.initCKPlayer();
  853. });
  854. }
  855. });
  856. }
  857. }
  858. } else if (/^rtmp:/.test(playParams)) {
  859. if (isMobile) {
  860. this.opt.cur++;
  861. this.tryPlay(playParams);
  862. return;
  863. } else {
  864. addJs(ckplayerJS, function () {
  865. me.initCKPlayer(playParams);
  866. });
  867. }
  868. } else if (/^wss:|^ws:/.test(playParams)) {
  869. /*
  870. * WS协议的JSMpeg的不支持IE11以下的版本
  871. * 开放平台官网不支持IE8打开,所以官网上面不兼容两个人版本IE9 ,和IE10
  872. *
  873. * */
  874. if (!ltIE11()) {
  875. addJs(mpegJS, function () {
  876. me.initJSmpeg(playParams);
  877. });
  878. } else {
  879. alert('WS协议不支持Ie11以下的浏览器!请使用IE11,或者更高版本的浏览器');
  880. return;
  881. }
  882. } else if (/\.flv/.test(this.opt.currentSource)) {
  883. addJs(flv_js, function () {
  884. me.log("使用flv.js播放");
  885. me.initflv();
  886. });
  887. }
  888. }
  889. };
  890. // 初始化hls.js
  891. EZUIPlayer.prototype.initHLS = function (hlsURL) {
  892. var me = this;
  893. var hls = new Hls({ defaultAudioCodec: 'mp4a.40.2' }); // 萤石设备默认使用 AAC LC 音频编码
  894. hls.loadSource(hlsURL);
  895. hls.attachMedia(this.video);
  896. hls.on(Hls.Events.MANIFEST_PARSED, function () {
  897. if (me.opt.autoplay) {
  898. me.video.play();
  899. }
  900. me.initVideoEvent();
  901. });
  902. hls.on(Hls.Events.ERROR, function (event, data) {
  903. if (data.fatal) {
  904. switch (data.type) {
  905. case Hls.ErrorTypes.NETWORK_ERROR:
  906. // try to recover network error
  907. console.log("fatal network error encountered, try to recover");
  908. hls.startLoad();
  909. break;
  910. case Hls.ErrorTypes.MEDIA_ERROR:
  911. console.log("fatal media error encountered, try to recover");
  912. hls.recoverMediaError();
  913. break;
  914. default:
  915. // cannot recover
  916. hls.destroy();
  917. break;
  918. }
  919. }
  920. });
  921. this.hls = hls;
  922. };
  923. // 初始化ckplayer
  924. EZUIPlayer.prototype.initCKPlayer = function (url) {
  925. this.log('ckplayer初始化');
  926. var me = this;
  927. var events = {
  928. 'play': function () { me.emit('play') },
  929. 'pause': function () { me.emit('pause') },
  930. 'error': function () { me.emit('error') }
  931. };
  932. window.ckplayer_status = function () {
  933. me.log(arguments);
  934. events[arguments[0]] && events[arguments[0]]();
  935. };
  936. // 新增相同id的div标签,然后删除video标签
  937. this.videoFlash = document.createElement('DIV');
  938. this.video.parentNode.replaceChild(this.videoFlash, this.video);
  939. this.video = this.videoFlash;
  940. this.videoFlash.id = this.opt.parentId;
  941. var flashvars = null;
  942. // 如果rtmp服务器环境设置了视频暂停则断开链接
  943. // 需要修改ckplayer.js setup参数第30个值
  944. // 在播放暂停后点击播放是否采用重新链接的方式
  945. if (/^rtmp/.test(this.opt.currentSource)) {
  946. flashvars = {
  947. f: this.opt.currentSource,
  948. c: 0,
  949. p: this.opt.autoplay ? 1 : 0,
  950. i: this.opt.poster,
  951. lv: 1,
  952. loaded: 'loadHandler'
  953. };
  954. } else if (/\.m3u8/.test(this.opt.currentSource)) {
  955. flashvars = {
  956. s: 4, // 4-使用swf视频流插件播放
  957. f: m3u8SWF,
  958. a: this.opt.currentSource,
  959. c: 0, // 0-使用ckplayer.js的配置 1-使用ckplayer.xml的配置
  960. lv: 1, // 1-直播 0-普通方式
  961. p: this.opt.autoplay ? 1 : 0, // 1-默认播放 0-默认暂停
  962. i: this.opt.poster,
  963. loaded: 'loadHandler'
  964. };
  965. } else {
  966. flashvars = {
  967. f: this.opt.currentSource,
  968. c: 0,
  969. p: 1,
  970. loaded: 'loadHandler'
  971. };
  972. }
  973. var params = { bgcolor: '#FFF', allowFullScreen: true, allowScriptAccess: 'always', wmode: 'transparent' };
  974. this.flashId = this.opt.parentId + 'flashId';
  975. window.CKobject.embedSWF(ckplayerSWF, this.opt.parentId, this.flashId, this.opt.width, this.opt.height, flashvars, params);
  976. };
  977. EZUIPlayer.prototype.initVideoEvent = function () {
  978. var me = this;
  979. var EVENT = {
  980. 'loadstart': function (e) {
  981. me.log('loadstart...当浏览器开始查找音频/视频时...');
  982. me.emit('loadstart', e);
  983. },
  984. 'durationchange': function (e) {
  985. me.log('durationchange...当音频/视频的时长已更改时...');
  986. me.emit('durationchange', e);
  987. },
  988. 'loadedmetadata': function (e) {
  989. me.log('loadedmetadata...当浏览器已加载音频/视频的元数据时...');
  990. me.emit('loadedmetadata', e);
  991. },
  992. 'loadeddata': function (e) {
  993. me.log('loadeddata...当浏览器已加载音频/视频的当前帧时...');
  994. me.emit('loadeddata', e);
  995. },
  996. 'progress': function (e) {
  997. me.log('progress...当浏览器正在下载音频/视频时...');
  998. me.emit('progress', e);
  999. },
  1000. 'canplay': function (e) {
  1001. me.log('canplay...当浏览器可以播放音频/视频时...');
  1002. me.emit('canplay', e);
  1003. },
  1004. 'canplaythrough': function (e) {
  1005. me.log('canplaythrough...当浏览器可在不因缓冲而停顿的情况下进行播放时...');
  1006. me.emit('canplaythrough', e);
  1007. },
  1008. 'abort': function (e) {
  1009. me.log('abort...当音频/视频的加载已放弃时...');
  1010. me.emit('abort', e);
  1011. },
  1012. 'emptied': function (e) {
  1013. me.log('emptied...当目前的播放列表为空时...');
  1014. me.emit('emptied', e);
  1015. },
  1016. 'ended': function (e) {
  1017. me.log('ended...当目前的播放列表已结束时...');
  1018. me.emit('ended', e);
  1019. },
  1020. 'pause': function (e) {
  1021. me.log('pause...当音频/视频已暂停时...');
  1022. me.emit('pause', e);
  1023. },
  1024. 'play': function (e) {
  1025. me.log('play...当音频/视频已开始或不再暂停时...');
  1026. me.emit('play', e);
  1027. },
  1028. 'playing': function (e) {
  1029. me.log('playing...当音频/视频在已因缓冲而暂停或停止后已就绪时...');
  1030. me.emit('playing', e);
  1031. },
  1032. 'ratechange': function (e) {
  1033. me.log('ratechange...当音频/视频的播放速度已更改时...');
  1034. me.emit('ratechange', e);
  1035. },
  1036. 'seeked': function (e) {
  1037. me.log('seeked...当用户已移动/跳跃到音频/视频中的新位置时...');
  1038. me.emit('seeked', e);
  1039. },
  1040. 'seeking': function (e) {
  1041. me.log('seeking...当用户开始移动/跳跃到音频/视频中的新位置时...');
  1042. me.emit('seeking', e);
  1043. },
  1044. 'stalled': function (e) {
  1045. me.log('stalled...当浏览器尝试获取媒体数据,但数据不可用时...');
  1046. me.emit('stalled', e);
  1047. },
  1048. 'suspend': function (e) {
  1049. me.log('suspend...当浏览器刻意不获取媒体数据时...');
  1050. me.emit('suspend', e);
  1051. if (me.opt.autoplay) {
  1052. me.video.play();
  1053. }
  1054. },
  1055. 'timeupdate': function (e) {
  1056. //me.log('timeupdate...当目前的播放位置已更改时...');
  1057. me.emit('timeupdate', e);
  1058. },
  1059. 'volumechange': function (e) {
  1060. me.log('volumechange...当音量已更改时...');
  1061. me.emit('volumechange', e);
  1062. },
  1063. 'waiting': function (e) {
  1064. me.log('waiting...当视频由于需要缓冲下一帧而停止...');
  1065. me.emit('waiting', e);
  1066. },
  1067. 'error': function (e) {
  1068. me.log('error...当在音频/视频加载期间发生错误时...');
  1069. me.emit('error', e);
  1070. }
  1071. };
  1072. for (var i in EVENT) {
  1073. this.video.addEventListener(i, EVENT[i], false);
  1074. }
  1075. ios11Hack(this.video);
  1076. };
  1077. EZUIPlayer.prototype.initJSmpeg = function (jsmpegUrl) {
  1078. this.canvasEle = document.createElement('canvas');
  1079. this.canvasEle.style.width = this.opt.width;
  1080. this.canvasEle.style.height = this.opt.height;
  1081. this.video.parentNode.replaceChild(this.canvasEle, this.video);
  1082. this.canvasEle.id = this.opt.parentId;
  1083. var player;
  1084. if (player && player.destroy) {
  1085. player.destroy();
  1086. }
  1087. player = new JSMpeg.Player(jsmpegUrl, { canvas: this.canvasEle });
  1088. this.JSmpeg = player;
  1089. };
  1090. EZUIPlayer.prototype.initflv = function () {
  1091. if (flvjs.isSupported()) {
  1092. var player = this.video;
  1093. var hasControls = player.getAttribute('controls');
  1094. if (!hasControls) {
  1095. player.setAttribute('controls', true);
  1096. }
  1097. var flvPlayer = flvjs.createPlayer({
  1098. type: 'flv',
  1099. url: this.opt.currentSource,
  1100. isLive: true,
  1101. }, {
  1102. enableStashBuffer: true,
  1103. stashInitialSize: 128,
  1104. enableWorker: true
  1105. });
  1106. flvPlayer.attachMediaElement(player);
  1107. flvPlayer.load();
  1108. flvPlayer.play();
  1109. } else {
  1110. this.log("浏览器不支持flv播放");
  1111. throw new Error('浏览器不支持flv播放');
  1112. return;
  1113. }
  1114. this.flv = flvPlayer;
  1115. };
  1116. EZUIPlayer.prototype.play = function (params, playParams) {
  1117. //var index = params.index;
  1118. if (!!window['CKobject']) {
  1119. this.opt.autoplay = true;
  1120. this.initCKPlayer();
  1121. } else if (!!this.video) { // video播放 包含flv, hls
  1122. if (!!this.hls) { // hls开始播放依赖 this.hls
  1123. this.opt.autoplay = true;
  1124. this.hls.startLoad();
  1125. this.video.play();
  1126. } else if (!!this.JSmpeg) {
  1127. this.JSmpeg.play();
  1128. } else { // 其他开始播放使用原生video
  1129. this.opt.autoplay = true;
  1130. this.video.play();
  1131. }
  1132. } else if (!!this.jSPlugin) {
  1133. // 音频自动播放
  1134. var audioId = 0
  1135. if(playParams && playParams.audioId){
  1136. audioId = playParams.audioId;
  1137. }else if(playParams.audioId === -1) {
  1138. audioId = undefined;
  1139. }
  1140. var _this = this;
  1141. function getPlayParams(url) {
  1142. var websocketConnectUrl = url.split('?')[0].replace('/live', '').replace('/playback', '');
  1143. // console.log("playParams,",playParams,playParams.env.wsUrl)
  1144. if(playParams && playParams.env && playParams.env.wsUrl){
  1145. websocketConnectUrl= playParams.env.wsUrl;
  1146. }
  1147. var websocketStreamingParam = (url.indexOf('/live') === -1 ? url.indexOf('cloudplayback')!== -1 ? '/cloudplayback?' : '/playback?' : '/live?') + url.split('?')[1];
  1148. // 本地回放仅支持主码流 - 2019-11-05 修订
  1149. if(websocketStreamingParam.indexOf('/playback') !==-1){
  1150. websocketStreamingParam = websocketStreamingParam.replace("stream=2",'stream=1');
  1151. }
  1152. // 本地回放仅支持主码流
  1153. return { websocketConnectUrl: websocketConnectUrl, websocketStreamingParam: websocketStreamingParam }
  1154. }
  1155. if (!params || typeof params.index === 'undefined') {
  1156. _this.opt.sources.forEach(function (item, index) {
  1157. if(getQueryString('dev',item)){
  1158. _this.log("开始播放, 第" + (index+1)+ '路,' + '地址:' + item);
  1159. _this.loadingSet(index,{text:'准备播放...',color:'#fff'})
  1160. // 设置秘钥 - 如果地址中包含秘钥参数,播放前配置到JSPlugin对应实例中
  1161. var validateCode = getQueryString('checkCode', item);
  1162. if (validateCode) {
  1163. _this.log('设置秘钥,视频路数:' + (index + 1) + '验证码:' + validateCode)
  1164. _this.jSPlugin.JS_SetSecretKey(index, validateCode);
  1165. }
  1166. var playST = new Date().getTime();
  1167. _this.jSPlugin.JS_Play(getPlayParams(item).websocketConnectUrl, { playURL: getPlayParams(item).websocketStreamingParam }, index).then(function () {
  1168. _this.log('播放成功,当前播放第' + (index + 1) + '路');
  1169. _this.loadingSet(index,{text:'播放成功...'});
  1170. //单次播放日志上报
  1171. ezuikitDclog({
  1172. systemName: PERFORMANCE_EZUIKIT,
  1173. bn: 2,
  1174. browser: JSON.stringify(getBrowserInfo()),
  1175. duration: new Date().getTime() - playST,
  1176. rt: 200,
  1177. })
  1178. // 播放成功
  1179. ezuikitDclog({
  1180. systemName: PERFORMANCE_EZUIKIT,
  1181. bn: 99,
  1182. browser: JSON.stringify(getBrowserInfo()),
  1183. duration: new Date().getTime() - playStartTime,
  1184. rt: 200,
  1185. })
  1186. _this.loadingEnd(index);
  1187. // 默认开启声音
  1188. // 默认开启第一路声音
  1189. if (typeof(audioId) !== "undefined" && audioId === index) {
  1190. _this.log("默认开启第1路声音");
  1191. setTimeout(function(){
  1192. var openSoundRT = _this.jSPlugin.JS_OpenSound(0);
  1193. openSoundRT === 0 ? _this.log('开启声音成功') : _this.log('开启声音失败','error');
  1194. }, 100)
  1195. }
  1196. // 播放成功回调
  1197. if (params && params.handleSuccess) {
  1198. params.handleSuccess();
  1199. }
  1200. //
  1201. // 播放成功日志上报
  1202. var PlTp = 1;
  1203. if(playParams && playParams.url){
  1204. if(playParams.url.indexOf('rec')!== -1){
  1205. PlTp = 2;
  1206. }
  1207. }
  1208. dclog({
  1209. systemName: PLAY_MAIN,
  1210. playurl: encodeURIComponent(item),
  1211. Time: (new Date()).Format('yyyy-MM-dd hh:mm:ss.S'),
  1212. Enc: 0, // 0 不加密 1 加密
  1213. PlTp: PlTp, // 1 直播 2 回放
  1214. Via: 2, // 2 服务端取流
  1215. ErrCd: 0,
  1216. OpId: uuid(),
  1217. Cost: (new Date()).getTime() - _this.initTime, // 毫秒数
  1218. Serial: getQueryString('dev',item),
  1219. Channel: getQueryString('chn',item),
  1220. });
  1221. }, function (err) {
  1222. _this.log('播放失败' + JSON.stringify(err), 'error');
  1223. var errorInfo = JSON.parse(_this.errorCode).find(function (item) { return item.detailCode.substr(-4) == err.oError.errorCode });
  1224. ezuikitDclog({
  1225. systemName: PERFORMANCE_EZUIKIT,
  1226. bn: 2,
  1227. browser: JSON.stringify(getBrowserInfo()),
  1228. duration: new Date().getTime() - playStartTime,
  1229. rt: err.oError ? err.oError.errorCode : 500,
  1230. msg: errorInfo ? errorInfo.description : '播放过程其他错误'
  1231. })
  1232. var msg = errorInfo ? errorInfo.description : '播放过程其他错误';
  1233. _this.loadingSet(index,{text:msg,color:'red'});
  1234. dclog({
  1235. systemName: PLAY_MAIN,
  1236. playurl: encodeURIComponent(item),
  1237. cost: -1,
  1238. ErrCd: -1,
  1239. OpId: uuid(),
  1240. Serial: getQueryString('dev',item),
  1241. Channel: getQueryString('chn',item),
  1242. });
  1243. if (params && params.handleError) {
  1244. var errorInfo = JSON.parse(_this.errorCode).find(function (item) { return item.detailCode.substr(-4) == err.oError.errorCode })
  1245. params.handleError({ retcode: err.oError.errorCode, msg: errorInfo ? errorInfo.description : '其他错误' });
  1246. }
  1247. })
  1248. } else {
  1249. if(isJSON(item) && JSON.parse(item).msg){
  1250. _this.loadingSet(index,{text:JSON.parse(item).msg,color:'red'})
  1251. }
  1252. }
  1253. })
  1254. }
  1255. }
  1256. };
  1257. EZUIPlayer.prototype.initDecoder = function (playParams) {
  1258. this.opt.id = playParams.id;
  1259. this.log("初始化解码器---开始");
  1260. var _this = this;
  1261. var initDecoderDurationST = new Date().getTime();
  1262. // DOM id
  1263. function initDecoder(resolve, reject) {
  1264. var jsPluginPath = playParams.decoderPath + '/js/jsPlugin-1.2.0.min.js';
  1265. /** 初始化解码器 */
  1266. addJs(jsPluginPath, function () {
  1267. _this.log("下载解码器完成,开始初始化");
  1268. /* decoder 属性配置 */
  1269. _this.jSPlugin = new JSPlugin({
  1270. szId: playParams.id,
  1271. iType: 2,
  1272. iMode: 0,
  1273. iWidth: playParams.width || 600,
  1274. iHeight: playParams.height || 400,
  1275. iMaxSplit: Math.ceil(Math.sqrt(playParams.url.split(",").length)),
  1276. iCurrentSplit: playParams.splitBasis || Math.ceil(Math.sqrt(playParams.url.split(",").length)),
  1277. szBasePath: playParams.decoderPath + '/js',
  1278. });
  1279. // 注册全屏事件
  1280. window.onresize = function () {
  1281. _this.jSPlugin.JS_Resize(playParams.width || 600, playParams.height || 400);
  1282. }
  1283. _this.log("初始化解码器----完成");
  1284. // 执行一次初始化解码器服务请求上报
  1285. ezuikitDclog({
  1286. systemName: PERFORMANCE_EZUIKIT,
  1287. bn: 1,
  1288. browser: JSON.stringify(getBrowserInfo()),
  1289. duration: new Date().getTime() - initDecoderDurationST,
  1290. rt: 200,
  1291. })
  1292. resolve('200 OK')
  1293. });
  1294. /**
  1295. * 加载错误码
  1296. * 错误码维护平台 - omm管理系统
  1297. */
  1298. function success(data) {
  1299. if (data.code == 200) {
  1300. if (!window.localStorage) {
  1301. return false;
  1302. } else {
  1303. var storage = window.localStorage;
  1304. //写入a字段
  1305. storage["errorCode"] = JSON.stringify(data.data);
  1306. _this.errorCode = storage['errorCode'];
  1307. }
  1308. }
  1309. }
  1310. if (!window.localStorage) {
  1311. request(
  1312. playParams.decoderPath + "/js/errorCode.json",
  1313. "get",
  1314. {
  1315. language: 1,
  1316. time: new Date().getTime(),
  1317. appKey: '26810f3acd794862b608b6cfbc32a6b8',
  1318. },
  1319. '',
  1320. success
  1321. );
  1322. } else {
  1323. var storage = window.localStorage;
  1324. var errorCode = storage.errorCode;
  1325. if (!errorCode) {
  1326. request(
  1327. playParams.decoderPath + "/js/errorCode.json",
  1328. "get",
  1329. {
  1330. language: 1,
  1331. time: new Date().getTime(),
  1332. appKey: '26810f3acd794862b608b6cfbc32a6b8',
  1333. },
  1334. '',
  1335. success
  1336. );
  1337. } else {
  1338. _this.errorCode = storage['errorCode'];
  1339. }
  1340. }
  1341. }
  1342. var initDecoderPromise = new Promise(initDecoder);
  1343. return initDecoderPromise;
  1344. }
  1345. EZUIPlayer.prototype.stop = function (i) {
  1346. // 执行停止
  1347. this.log("停止播放" + this.opt.currentSource);
  1348. this.opt.autoplay = false;
  1349. if (!!window['CKobject']) {
  1350. //CKobject.getObjectById(this.flashId).destroy();
  1351. this.video.src = ""
  1352. // this.video.remove();
  1353. } else if (!!this.video) {
  1354. if (!!this.hls) { // hls停止依赖this.hls
  1355. // 通过暂停停止播放
  1356. this.video.pause();
  1357. this.video.src = ""
  1358. // 停止取流
  1359. this.hls.stopLoad();
  1360. } else if (!!this.flv) {
  1361. this.flv.pause();
  1362. this.flv.unload();
  1363. this.flv.detachMediaElement();
  1364. this.flv.destroy();
  1365. this.flv = null;
  1366. } else if (!!this.JSmpeg) {
  1367. this.JSmpeg.stop();
  1368. // this.JSmpeg.destroy();
  1369. }
  1370. } else if (!!this.jSPlugin) {
  1371. var _this = this;
  1372. if (typeof i === "undefined") {
  1373. return this.jSPlugin.JS_Stop(0).then(function () {
  1374. _this.log("停止播放成功" + _this.opt.currentSource);
  1375. console.log("stop success");
  1376. // 额外销毁worker
  1377. _this.jSPlugin.JS_DestroyWorker();
  1378. _this.loadingEnd(0);
  1379. //removeChild(0);
  1380. }, function () {
  1381. _this.log("停止播放失败" + _this.opt.currentSource);
  1382. console.log("stop failed");
  1383. });
  1384. } else {
  1385. return this.jSPlugin.JS_Stop(i).then(function () {
  1386. _this.log("第" + i+"路停止播放成功" + _this.opt.currentSource);
  1387. _this.loadingEnd(i);
  1388. console.log("stop success");
  1389. }, function () {
  1390. _this.log("第" + i+"路停止播放失败" + _this.opt.currentSource);
  1391. _this.loadingEnd(i);
  1392. console.log("stop failed");
  1393. });
  1394. // 额外销毁worker - 多窗口暂不销毁
  1395. // this.jSPlugin.JS_DestroyWorker();
  1396. //removeChild(i);
  1397. }
  1398. function removeChild(index) {
  1399. var windDOM = document.getElementById(_this.opt.id).childNodes[0].childNodes[index];
  1400. var childs = windDOM.childNodes;
  1401. for (var i = childs.length - 1; i >= 0; i--) {
  1402. windDOM.removeChild(childs[i]);
  1403. }
  1404. }
  1405. }
  1406. };
  1407. // 获取OSD时间
  1408. // EZUIPlayer.prototype.getOSDTime = function (callback, iWind) {
  1409. // if (!!this.jSPlugin) {
  1410. // this.jSPlugin.JS_GetOSDTime(iWind || 0).then(function (iTime) {
  1411. // callback(iTime * 1000);
  1412. // }, function (err) {
  1413. // console.log("get OSD Time error", err);
  1414. // });
  1415. // } else {
  1416. // throw new Error("Method not support");
  1417. // }
  1418. // }
  1419. // 返回promise的getOSDTime方法
  1420. EZUIPlayer.prototype.getOSDTime = function(wNum) {
  1421. const _this = this;
  1422. if (!!this.jSPlugin) {
  1423. return _this.jSPlugin.JS_GetOSDTime(wNum || 0);
  1424. } else {
  1425. throw new Error("Method not support");
  1426. }
  1427. }
  1428. // 开启声音
  1429. EZUIPlayer.prototype.openSound = function (iWind) {
  1430. if (!!this.jSPlugin) {
  1431. var openSoundRT = this.jSPlugin.JS_OpenSound(iWind || 0);
  1432. openSoundRT === 0 ? this.log('开启声音成功') : this.log('开启声音失败','error');
  1433. return openSoundRT;
  1434. } else {
  1435. throw new Error("Method not support");
  1436. }
  1437. }
  1438. // 全屏
  1439. EZUIPlayer.prototype.fullScreen = function () {
  1440. if (!!this.jSPlugin) {
  1441. return this.jSPlugin.JS_FullScreenDisplay(1);
  1442. } else {
  1443. throw new Error("Method not support");
  1444. }
  1445. }
  1446. // 关闭声音
  1447. EZUIPlayer.prototype.closeSound = function (iWind) {
  1448. if (!!this.jSPlugin) {
  1449. var closeSoundRT = this.jSPlugin.JS_CloseSound(iWind || 0);
  1450. closeSoundRT === 0 ? this.log('关闭声音成功') : this.log('关闭声音失败','error');
  1451. return closeSoundRT;
  1452. } else {
  1453. throw new Error("Method not support");
  1454. }
  1455. }
  1456. // 视频截图
  1457. EZUIPlayer.prototype.capturePicture = function (iWind, pictureName) {
  1458. if (!!this.jSPlugin) {
  1459. return this.jSPlugin.JS_CapturePicture(iWind, pictureName)
  1460. } else {
  1461. throw new Error("Method not support");
  1462. }
  1463. }
  1464. // 开始录像
  1465. EZUIPlayer.prototype.startSave = function (iWind, fileName) {
  1466. if (!!this.jSPlugin) {
  1467. this.log("开始录制录像");
  1468. return this.jSPlugin.JS_StartSave(iWind, fileName)
  1469. } else {
  1470. throw new Error("Method not support");
  1471. }
  1472. }
  1473. // 结束录像
  1474. EZUIPlayer.prototype.stopSave = function (iWind) {
  1475. if (!!this.jSPlugin) {
  1476. return this.jSPlugin.JS_StopSave(iWind);
  1477. this.log("结束录制录像");
  1478. } else {
  1479. throw new Error("Method not support");
  1480. }
  1481. }
  1482. EZUIPlayer.prototype.reSize = function (width,height) {
  1483. if (!!this.jSPlugin) {
  1484. return this.jSPlugin.JS_Resize(width,height);
  1485. } else {
  1486. throw new Error("Method not support");
  1487. }
  1488. }
  1489. EZUIPlayer.prototype.pause = function () {
  1490. this.opt.autoplay = false;
  1491. if (!!window['CKobject']) {
  1492. CKobject.getObjectById(this.flashId).videoPause();
  1493. } else if (!!this.video) {
  1494. if (!!this.JSmpeg) {
  1495. this.JSmpeg.pause();
  1496. } else {
  1497. this.video.pause();
  1498. }
  1499. } else if (!!this.jSPlugin) {
  1500. this.jSPlugin.JS_Pause(0).then(function () {
  1501. }, function () {
  1502. });
  1503. }
  1504. };
  1505. EZUIPlayer.prototype.load = function () {
  1506. if (!!window['CKobject']) {
  1507. // flash load
  1508. } else if (!!this.video) {
  1509. this.video.load();
  1510. }
  1511. };
  1512. // 开启电子放大
  1513. EZUIPlayer.prototype.enableZoom = function(iWind) {
  1514. if (!!this.jSPlugin) {
  1515. return this.jSPlugin.JS_EnableZoom(iWind || 0);
  1516. } else {
  1517. throw new Error("Method not support");
  1518. }
  1519. }
  1520. // 关闭电子放大
  1521. EZUIPlayer.prototype.closeZoom = function(iWind) {
  1522. if (!!this.jSPlugin) {
  1523. return this.jSPlugin.JS_DisableZoom(iWind || 0);
  1524. } else {
  1525. throw new Error("Method not support");
  1526. }
  1527. }
  1528. // iOS11手机HLS直播在m3u8响应时间过长后不继续请求的hack
  1529. 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;});}
  1530. function ltIE11() {var userAgent = navigator.userAgent; var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;if (isIE) {return true;} else {return false;}}
  1531. var EZUIKit = {
  1532. 'EZUIPlayer': EZUIPlayer,
  1533. };
  1534. // 兼容1.4 以下旧版本
  1535. // var EZUIPlayer = EZuikit.EZUIPlayer;
  1536. if (!noGlobal) {
  1537. window.EZUIKit = EZUIKit;
  1538. // 兼容1.4 以下旧版本
  1539. window.EZUIPlayer = EZUIPlayer;
  1540. }
  1541. return EZUIKit;
  1542. });