ezuikit.js 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640
  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(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. if (!ltIE11()) {
  884. addJs(ckplayerJS, function () {
  885. me.initCKPlayer();
  886. });
  887. } else {
  888. addJs(flv_js, function () {
  889. me.log("使用flv.js播放");
  890. me.initflv();
  891. });
  892. }
  893. }
  894. }
  895. };
  896. // 初始化hls.js
  897. EZUIPlayer.prototype.initHLS = function (hlsURL) {
  898. var me = this;
  899. var hls = new Hls({ defaultAudioCodec: 'mp4a.40.2' }); // 萤石设备默认使用 AAC LC 音频编码
  900. hls.loadSource(hlsURL);
  901. hls.attachMedia(this.video);
  902. hls.on(Hls.Events.MANIFEST_PARSED, function () {
  903. if (me.opt.autoplay) {
  904. me.video.play();
  905. }
  906. me.initVideoEvent();
  907. });
  908. hls.on(Hls.Events.ERROR, function (event, data) {
  909. if (data.fatal) {
  910. switch (data.type) {
  911. case Hls.ErrorTypes.NETWORK_ERROR:
  912. // try to recover network error
  913. console.log("fatal network error encountered, try to recover");
  914. hls.startLoad();
  915. break;
  916. case Hls.ErrorTypes.MEDIA_ERROR:
  917. console.log("fatal media error encountered, try to recover");
  918. hls.recoverMediaError();
  919. break;
  920. default:
  921. // cannot recover
  922. hls.destroy();
  923. break;
  924. }
  925. }
  926. });
  927. this.hls = hls;
  928. };
  929. // 初始化ckplayer
  930. EZUIPlayer.prototype.initCKPlayer = function (url) {
  931. this.log('ckplayer初始化');
  932. var me = this;
  933. var events = {
  934. 'play': function () { me.emit('play') },
  935. 'pause': function () { me.emit('pause') },
  936. 'error': function () { me.emit('error') }
  937. };
  938. window.ckplayer_status = function () {
  939. me.log(arguments);
  940. events[arguments[0]] && events[arguments[0]]();
  941. };
  942. // 新增相同id的div标签,然后删除video标签
  943. this.videoFlash = document.createElement('DIV');
  944. this.video.parentNode.replaceChild(this.videoFlash, this.video);
  945. this.video = this.videoFlash;
  946. this.videoFlash.id = this.opt.parentId;
  947. var flashvars = null;
  948. // 如果rtmp服务器环境设置了视频暂停则断开链接
  949. // 需要修改ckplayer.js setup参数第30个值
  950. // 在播放暂停后点击播放是否采用重新链接的方式
  951. if (/^rtmp/.test(this.opt.currentSource)) {
  952. flashvars = {
  953. f: this.opt.currentSource,
  954. c: 0,
  955. p: this.opt.autoplay ? 1 : 0,
  956. i: this.opt.poster,
  957. lv: 1,
  958. loaded: 'loadHandler'
  959. };
  960. } else if (/\.m3u8/.test(this.opt.currentSource)) {
  961. flashvars = {
  962. s: 4, // 4-使用swf视频流插件播放
  963. f: m3u8SWF,
  964. a: this.opt.currentSource,
  965. c: 0, // 0-使用ckplayer.js的配置 1-使用ckplayer.xml的配置
  966. lv: 1, // 1-直播 0-普通方式
  967. p: this.opt.autoplay ? 1 : 0, // 1-默认播放 0-默认暂停
  968. i: this.opt.poster,
  969. loaded: 'loadHandler'
  970. };
  971. } else {
  972. flashvars = {
  973. f: this.opt.currentSource,
  974. c: 0,
  975. p: 1,
  976. loaded: 'loadHandler'
  977. };
  978. }
  979. var params = { bgcolor: '#FFF', allowFullScreen: true, allowScriptAccess: 'always', wmode: 'transparent' };
  980. this.flashId = this.opt.parentId + 'flashId';
  981. window.CKobject.embedSWF(ckplayerSWF, this.opt.parentId, this.flashId, this.opt.width, this.opt.height, flashvars, params);
  982. };
  983. EZUIPlayer.prototype.initVideoEvent = function () {
  984. var me = this;
  985. var EVENT = {
  986. 'loadstart': function (e) {
  987. me.log('loadstart...当浏览器开始查找音频/视频时...');
  988. me.emit('loadstart', e);
  989. },
  990. 'durationchange': function (e) {
  991. me.log('durationchange...当音频/视频的时长已更改时...');
  992. me.emit('durationchange', e);
  993. },
  994. 'loadedmetadata': function (e) {
  995. me.log('loadedmetadata...当浏览器已加载音频/视频的元数据时...');
  996. me.emit('loadedmetadata', e);
  997. },
  998. 'loadeddata': function (e) {
  999. me.log('loadeddata...当浏览器已加载音频/视频的当前帧时...');
  1000. me.emit('loadeddata', e);
  1001. },
  1002. 'progress': function (e) {
  1003. me.log('progress...当浏览器正在下载音频/视频时...');
  1004. me.emit('progress', e);
  1005. },
  1006. 'canplay': function (e) {
  1007. me.log('canplay...当浏览器可以播放音频/视频时...');
  1008. me.emit('canplay', e);
  1009. },
  1010. 'canplaythrough': function (e) {
  1011. me.log('canplaythrough...当浏览器可在不因缓冲而停顿的情况下进行播放时...');
  1012. me.emit('canplaythrough', e);
  1013. },
  1014. 'abort': function (e) {
  1015. me.log('abort...当音频/视频的加载已放弃时...');
  1016. me.emit('abort', e);
  1017. },
  1018. 'emptied': function (e) {
  1019. me.log('emptied...当目前的播放列表为空时...');
  1020. me.emit('emptied', e);
  1021. },
  1022. 'ended': function (e) {
  1023. me.log('ended...当目前的播放列表已结束时...');
  1024. me.emit('ended', e);
  1025. },
  1026. 'pause': function (e) {
  1027. me.log('pause...当音频/视频已暂停时...');
  1028. me.emit('pause', e);
  1029. },
  1030. 'play': function (e) {
  1031. me.log('play...当音频/视频已开始或不再暂停时...');
  1032. me.emit('play', e);
  1033. },
  1034. 'playing': function (e) {
  1035. me.log('playing...当音频/视频在已因缓冲而暂停或停止后已就绪时...');
  1036. me.emit('playing', e);
  1037. },
  1038. 'ratechange': function (e) {
  1039. me.log('ratechange...当音频/视频的播放速度已更改时...');
  1040. me.emit('ratechange', e);
  1041. },
  1042. 'seeked': function (e) {
  1043. me.log('seeked...当用户已移动/跳跃到音频/视频中的新位置时...');
  1044. me.emit('seeked', e);
  1045. },
  1046. 'seeking': function (e) {
  1047. me.log('seeking...当用户开始移动/跳跃到音频/视频中的新位置时...');
  1048. me.emit('seeking', e);
  1049. },
  1050. 'stalled': function (e) {
  1051. me.log('stalled...当浏览器尝试获取媒体数据,但数据不可用时...');
  1052. me.emit('stalled', e);
  1053. },
  1054. 'suspend': function (e) {
  1055. me.log('suspend...当浏览器刻意不获取媒体数据时...');
  1056. me.emit('suspend', e);
  1057. if (me.opt.autoplay) {
  1058. me.video.play();
  1059. }
  1060. },
  1061. 'timeupdate': function (e) {
  1062. //me.log('timeupdate...当目前的播放位置已更改时...');
  1063. me.emit('timeupdate', e);
  1064. },
  1065. 'volumechange': function (e) {
  1066. me.log('volumechange...当音量已更改时...');
  1067. me.emit('volumechange', e);
  1068. },
  1069. 'waiting': function (e) {
  1070. me.log('waiting...当视频由于需要缓冲下一帧而停止...');
  1071. me.emit('waiting', e);
  1072. },
  1073. 'error': function (e) {
  1074. me.log('error...当在音频/视频加载期间发生错误时...');
  1075. me.emit('error', e);
  1076. }
  1077. };
  1078. for (var i in EVENT) {
  1079. this.video.addEventListener(i, EVENT[i], false);
  1080. }
  1081. ios11Hack(this.video);
  1082. };
  1083. EZUIPlayer.prototype.initJSmpeg = function (jsmpegUrl) {
  1084. this.canvasEle = document.createElement('canvas');
  1085. this.canvasEle.style.width = this.opt.width;
  1086. this.canvasEle.style.height = this.opt.height;
  1087. this.video.parentNode.replaceChild(this.canvasEle, this.video);
  1088. this.canvasEle.id = this.opt.parentId;
  1089. var player;
  1090. if (player && player.destroy) {
  1091. player.destroy();
  1092. }
  1093. player = new JSMpeg.Player(jsmpegUrl, { canvas: this.canvasEle });
  1094. this.JSmpeg = player;
  1095. };
  1096. EZUIPlayer.prototype.initflv = function () {
  1097. if (flvjs.isSupported()) {
  1098. var player = this.video;
  1099. var hasControls = player.getAttribute('controls');
  1100. if (!hasControls) {
  1101. player.setAttribute('controls', true);
  1102. }
  1103. var flvPlayer = flvjs.createPlayer({
  1104. type: 'flv',
  1105. url: this.opt.currentSource,
  1106. isLive: true,
  1107. }, {
  1108. enableStashBuffer: true,
  1109. stashInitialSize: 128,
  1110. enableWorker: true
  1111. });
  1112. flvPlayer.attachMediaElement(player);
  1113. flvPlayer.load();
  1114. flvPlayer.play();
  1115. } else {
  1116. this.log("浏览器不支持flv播放");
  1117. throw new Error('浏览器不支持flv播放');
  1118. return;
  1119. }
  1120. this.flv = flvPlayer;
  1121. };
  1122. EZUIPlayer.prototype.rePlay = function(playParams){
  1123. this.loadingStart();
  1124. // _this.loadingSet(0,{text:'获取设备播放地址'})
  1125. var _this = this;
  1126. var getRealUrl = this.getRealUrl(playParams);
  1127. /**是否自动播放 */
  1128. if (isPromise(getRealUrl)) {
  1129. getRealUrl.then(function (data) {
  1130. _this.play(playParams);
  1131. })
  1132. .catch(function (err) {
  1133. console.log("播放错误",err)
  1134. });
  1135. }
  1136. }
  1137. EZUIPlayer.prototype.play = function (playParams) {
  1138. //var index = params.index;
  1139. if (!!window['CKobject']) {
  1140. this.opt.autoplay = true;
  1141. this.initCKPlayer();
  1142. } else if (!!this.video) { // video播放 包含flv, hls
  1143. if (!!this.hls) { // hls开始播放依赖 this.hls
  1144. this.opt.autoplay = true;
  1145. this.hls.startLoad();
  1146. this.video.play();
  1147. } else if (!!this.JSmpeg) {
  1148. this.JSmpeg.play();
  1149. } else { // 其他开始播放使用原生video
  1150. this.opt.autoplay = true;
  1151. this.video.play();
  1152. }
  1153. } else if (!!this.jSPlugin) {
  1154. // 音频自动播放
  1155. var audioId = 0
  1156. if(playParams && playParams.audioId){
  1157. audioId = playParams.audioId;
  1158. }else if(playParams.audioId === -1) {
  1159. audioId = undefined;
  1160. }
  1161. var _this = this;
  1162. function getPlayParams(url) {
  1163. var websocketConnectUrl = url.split('?')[0].replace('/live', '').replace('/playback', '');
  1164. // console.log("playParams,",playParams,playParams.env.wsUrl)
  1165. if(playParams && playParams.env && playParams.env.wsUrl){
  1166. websocketConnectUrl= playParams.env.wsUrl;
  1167. }
  1168. var websocketStreamingParam = (url.indexOf('/live') === -1 ? url.indexOf('cloudplayback')!== -1 ? '/cloudplayback?' : '/playback?' : '/live?') + url.split('?')[1];
  1169. // 本地回放仅支持主码流 - 2019-11-05 修订
  1170. if(websocketStreamingParam.indexOf('/playback') !==-1){
  1171. websocketStreamingParam = websocketStreamingParam.replace("stream=2",'stream=1');
  1172. }
  1173. // 本地回放仅支持主码流
  1174. return { websocketConnectUrl: websocketConnectUrl, websocketStreamingParam: websocketStreamingParam }
  1175. }
  1176. if (!playParams || typeof playParams.index === 'undefined') {
  1177. _this.opt.sources.forEach(function (item, index) {
  1178. if(getQueryString('dev',item)){
  1179. _this.log("开始播放, 第" + (index+1)+ '路,' + '地址:' + item);
  1180. _this.loadingSet(index,{text:'准备播放...',color:'#fff'})
  1181. // 设置秘钥 - 如果地址中包含秘钥参数,播放前配置到JSPlugin对应实例中
  1182. var validateCode = getQueryString('checkCode', item);
  1183. if (validateCode) {
  1184. _this.log('设置秘钥,视频路数:' + (index + 1) + '验证码:' + validateCode)
  1185. _this.jSPlugin.JS_SetSecretKey(index, validateCode);
  1186. }
  1187. var playST = new Date().getTime();
  1188. _this.jSPlugin.JS_Play(getPlayParams(item).websocketConnectUrl, { playURL: getPlayParams(item).websocketStreamingParam }, index).then(function () {
  1189. _this.log('播放成功,当前播放第' + (index + 1) + '路');
  1190. _this.loadingSet(index,{text:'播放成功...'});
  1191. //单次播放日志上报
  1192. ezuikitDclog({
  1193. systemName: PERFORMANCE_EZUIKIT,
  1194. bn: 2,
  1195. browser: JSON.stringify(getBrowserInfo()),
  1196. duration: new Date().getTime() - playST,
  1197. rt: 200,
  1198. })
  1199. // 播放成功
  1200. ezuikitDclog({
  1201. systemName: PERFORMANCE_EZUIKIT,
  1202. bn: 99,
  1203. browser: JSON.stringify(getBrowserInfo()),
  1204. duration: new Date().getTime() - playStartTime,
  1205. rt: 200,
  1206. })
  1207. _this.loadingEnd(index);
  1208. // 默认开启声音
  1209. // 默认开启第一路声音
  1210. if (typeof(audioId) !== "undefined" && audioId === index) {
  1211. _this.log("默认开启第1路声音");
  1212. setTimeout(function(){
  1213. var openSoundRT = _this.jSPlugin.JS_OpenSound(0);
  1214. openSoundRT === 0 ? _this.log('开启声音成功') : _this.log('开启声音失败','error');
  1215. }, 100)
  1216. }
  1217. // 播放成功回调
  1218. if (playParams && playParams.handleSuccess) {
  1219. playParams.handleSuccess();
  1220. }
  1221. //
  1222. // 播放成功日志上报
  1223. var PlTp = 1;
  1224. if(playParams && playParams.url){
  1225. if(playParams.url.indexOf('rec')!== -1){
  1226. PlTp = 2;
  1227. }
  1228. }
  1229. dclog({
  1230. systemName: PLAY_MAIN,
  1231. playurl: encodeURIComponent(item),
  1232. Time: (new Date()).Format('yyyy-MM-dd hh:mm:ss.S'),
  1233. Enc: 0, // 0 不加密 1 加密
  1234. PlTp: PlTp, // 1 直播 2 回放
  1235. Via: 2, // 2 服务端取流
  1236. ErrCd: 0,
  1237. OpId: uuid(),
  1238. Cost: (new Date()).getTime() - _this.initTime, // 毫秒数
  1239. Serial: getQueryString('dev',item),
  1240. Channel: getQueryString('chn',item),
  1241. });
  1242. }, function (err) {
  1243. _this.log('播放失败' + JSON.stringify(err), 'error');
  1244. var errorInfo = JSON.parse(_this.errorCode).find(function (item) { return item.detailCode.substr(-4) == err.oError.errorCode });
  1245. ezuikitDclog({
  1246. systemName: PERFORMANCE_EZUIKIT,
  1247. bn: 2,
  1248. browser: JSON.stringify(getBrowserInfo()),
  1249. duration: new Date().getTime() - playStartTime,
  1250. rt: err.oError ? err.oError.errorCode : 500,
  1251. msg: errorInfo ? errorInfo.description : '播放过程其他错误'
  1252. })
  1253. var msg = errorInfo ? errorInfo.description : '播放过程其他错误';
  1254. _this.loadingSet(index,{text:msg,color:'red'});
  1255. dclog({
  1256. systemName: PLAY_MAIN,
  1257. playurl: encodeURIComponent(item),
  1258. cost: -1,
  1259. ErrCd: -1,
  1260. OpId: uuid(),
  1261. Serial: getQueryString('dev',item),
  1262. Channel: getQueryString('chn',item),
  1263. });
  1264. if (playParams && playParams.handleError) {
  1265. var errorInfo = JSON.parse(_this.errorCode).find(function (item) { return item.detailCode.substr(-4) == err.oError.errorCode })
  1266. playParams.handleError({ retcode: err.oError.errorCode, msg: errorInfo ? errorInfo.description : '其他错误' });
  1267. }
  1268. })
  1269. } else {
  1270. if(isJSON(item) && JSON.parse(item).msg){
  1271. _this.loadingSet(index,{text:JSON.parse(item).msg,color:'red'})
  1272. }
  1273. }
  1274. })
  1275. }
  1276. }
  1277. };
  1278. EZUIPlayer.prototype.initDecoder = function (playParams) {
  1279. this.opt.id = playParams.id;
  1280. this.log("初始化解码器---开始");
  1281. var _this = this;
  1282. var initDecoderDurationST = new Date().getTime();
  1283. // DOM id
  1284. function initDecoder(resolve, reject) {
  1285. var jsPluginPath = playParams.decoderPath + '/js/jsPlugin-1.2.0.min.js';
  1286. /** 初始化解码器 */
  1287. addJs(jsPluginPath, function () {
  1288. _this.log("下载解码器完成,开始初始化");
  1289. /* decoder 属性配置 */
  1290. _this.jSPlugin = new JSPlugin({
  1291. szId: playParams.id,
  1292. iType: 2,
  1293. iMode: 0,
  1294. iWidth: playParams.width || 600,
  1295. iHeight: playParams.height || 400,
  1296. iMaxSplit: Math.ceil(Math.sqrt(playParams.url.split(",").length)),
  1297. iCurrentSplit: playParams.splitBasis || Math.ceil(Math.sqrt(playParams.url.split(",").length)),
  1298. szBasePath: playParams.decoderPath + '/js',
  1299. });
  1300. // 注册全屏事件
  1301. window.onresize = function () {
  1302. _this.jSPlugin.JS_Resize(playParams.width || 600, playParams.height || 400);
  1303. }
  1304. _this.log("初始化解码器----完成");
  1305. // 执行一次初始化解码器服务请求上报
  1306. ezuikitDclog({
  1307. systemName: PERFORMANCE_EZUIKIT,
  1308. bn: 1,
  1309. browser: JSON.stringify(getBrowserInfo()),
  1310. duration: new Date().getTime() - initDecoderDurationST,
  1311. rt: 200,
  1312. })
  1313. resolve('200 OK')
  1314. });
  1315. /**
  1316. * 加载错误码
  1317. * 错误码维护平台 - omm管理系统
  1318. */
  1319. function success(data) {
  1320. if (data.code == 200) {
  1321. if (!window.localStorage) {
  1322. return false;
  1323. } else {
  1324. var storage = window.localStorage;
  1325. //写入a字段
  1326. storage["errorCode"] = JSON.stringify(data.data);
  1327. _this.errorCode = storage['errorCode'];
  1328. }
  1329. }
  1330. }
  1331. if (!window.localStorage) {
  1332. request(
  1333. playParams.decoderPath + "/js/errorCode.json",
  1334. "get",
  1335. {
  1336. language: 1,
  1337. time: new Date().getTime(),
  1338. appKey: '26810f3acd794862b608b6cfbc32a6b8',
  1339. },
  1340. '',
  1341. success
  1342. );
  1343. } else {
  1344. var storage = window.localStorage;
  1345. var errorCode = storage.errorCode;
  1346. if (!errorCode) {
  1347. request(
  1348. playParams.decoderPath + "/js/errorCode.json",
  1349. "get",
  1350. {
  1351. language: 1,
  1352. time: new Date().getTime(),
  1353. appKey: '26810f3acd794862b608b6cfbc32a6b8',
  1354. },
  1355. '',
  1356. success
  1357. );
  1358. } else {
  1359. _this.errorCode = storage['errorCode'];
  1360. }
  1361. }
  1362. }
  1363. var initDecoderPromise = new Promise(initDecoder);
  1364. return initDecoderPromise;
  1365. }
  1366. EZUIPlayer.prototype.stop = function (i,unDestory) {
  1367. // 执行停止
  1368. this.log("停止播放" + this.opt.currentSource);
  1369. this.opt.autoplay = false;
  1370. if (!!window['CKobject']) {
  1371. //CKobject.getObjectById(this.flashId).destroy();
  1372. this.video.src = ""
  1373. // this.video.remove();
  1374. } else if (!!this.video) {
  1375. if (!!this.hls) { // hls停止依赖this.hls
  1376. // 通过暂停停止播放
  1377. this.video.pause();
  1378. this.video.src = ""
  1379. // 停止取流
  1380. this.hls.stopLoad();
  1381. } else if (!!this.flv) {
  1382. this.flv.pause();
  1383. this.flv.unload();
  1384. this.flv.detachMediaElement();
  1385. this.flv.destroy();
  1386. this.flv = null;
  1387. } else if (!!this.JSmpeg) {
  1388. this.JSmpeg.stop();
  1389. // this.JSmpeg.destroy();
  1390. }
  1391. } else if (!!this.jSPlugin) {
  1392. var _this = this;
  1393. if (typeof i === "undefined") {
  1394. return this.jSPlugin.JS_Stop(0).then(function () {
  1395. _this.log("停止播放成功" + _this.opt.currentSource);
  1396. console.log("stop success");
  1397. // 额外销毁worker
  1398. // _this.jSPlugin.JS_DestroyWorker();
  1399. _this.loadingEnd(0);
  1400. //removeChild(0);
  1401. }, function () {
  1402. _this.log("停止播放失败" + _this.opt.currentSource);
  1403. console.log("stop failed");
  1404. });
  1405. } else {
  1406. return this.jSPlugin.JS_Stop(i).then(function () {
  1407. _this.log("第" + i+"路停止播放成功" + _this.opt.currentSource);
  1408. _this.loadingEnd(i);
  1409. console.log("stop success");
  1410. }, function () {
  1411. _this.log("第" + i+"路停止播放失败" + _this.opt.currentSource);
  1412. _this.loadingEnd(i);
  1413. console.log("stop failed");
  1414. });
  1415. // 额外销毁worker - 多窗口暂不销毁
  1416. // this.jSPlugin.JS_DestroyWorker();
  1417. //removeChild(i);
  1418. }
  1419. }
  1420. };
  1421. EZUIPlayer.prototype.destroy = function (i) {
  1422. _this.jSPlugin.JS_DestroyWorker();
  1423. }
  1424. // 获取OSD时间
  1425. // EZUIPlayer.prototype.getOSDTime = function (callback, iWind) {
  1426. // if (!!this.jSPlugin) {
  1427. // this.jSPlugin.JS_GetOSDTime(iWind || 0).then(function (iTime) {
  1428. // callback(iTime * 1000);
  1429. // }, function (err) {
  1430. // console.log("get OSD Time error", err);
  1431. // });
  1432. // } else {
  1433. // throw new Error("Method not support");
  1434. // }
  1435. // }
  1436. // 返回promise的getOSDTime方法
  1437. EZUIPlayer.prototype.getOSDTime = function(wNum) {
  1438. const _this = this;
  1439. if (!!this.jSPlugin) {
  1440. return _this.jSPlugin.JS_GetOSDTime(wNum || 0);
  1441. } else {
  1442. throw new Error("Method not support");
  1443. }
  1444. }
  1445. // 返回promise的getOSDTime方法
  1446. EZUIPlayer.prototype.getVersion = function(wNum) {
  1447. const _this = this;
  1448. if (!!this.jSPlugin) {
  1449. console.log(_this.jSPlugin.JS_GetSdkVersion());
  1450. } else {
  1451. throw new Error("Method not support");
  1452. }
  1453. }
  1454. // 开启声音
  1455. EZUIPlayer.prototype.openSound = function (iWind) {
  1456. if (!!this.jSPlugin) {
  1457. var openSoundRT = this.jSPlugin.JS_OpenSound(iWind || 0);
  1458. openSoundRT === 0 ? this.log('开启声音成功') : this.log('开启声音失败','error');
  1459. return openSoundRT;
  1460. } else {
  1461. throw new Error("Method not support");
  1462. }
  1463. }
  1464. // 全屏
  1465. EZUIPlayer.prototype.fullScreen = function () {
  1466. if (!!this.jSPlugin) {
  1467. return this.jSPlugin.JS_FullScreenDisplay(1);
  1468. } else {
  1469. throw new Error("Method not support");
  1470. }
  1471. }
  1472. // 关闭声音
  1473. EZUIPlayer.prototype.closeSound = function (iWind) {
  1474. if (!!this.jSPlugin) {
  1475. var closeSoundRT = this.jSPlugin.JS_CloseSound(iWind || 0);
  1476. closeSoundRT === 0 ? this.log('关闭声音成功') : this.log('关闭声音失败','error');
  1477. return closeSoundRT;
  1478. } else {
  1479. throw new Error("Method not support");
  1480. }
  1481. }
  1482. // 视频截图
  1483. EZUIPlayer.prototype.capturePicture = function (iWind, pictureName) {
  1484. if (!!this.jSPlugin) {
  1485. return this.jSPlugin.JS_CapturePicture(iWind, pictureName)
  1486. } else {
  1487. throw new Error("Method not support");
  1488. }
  1489. }
  1490. // 开始录像
  1491. EZUIPlayer.prototype.startSave = function (iWind, fileName) {
  1492. if (!!this.jSPlugin) {
  1493. this.log("开始录制录像");
  1494. return this.jSPlugin.JS_StartSave(iWind, fileName)
  1495. } else {
  1496. throw new Error("Method not support");
  1497. }
  1498. }
  1499. // 结束录像
  1500. EZUIPlayer.prototype.stopSave = function (iWind) {
  1501. if (!!this.jSPlugin) {
  1502. return this.jSPlugin.JS_StopSave(iWind);
  1503. this.log("结束录制录像");
  1504. } else {
  1505. throw new Error("Method not support");
  1506. }
  1507. }
  1508. EZUIPlayer.prototype.reSize = function (width,height) {
  1509. if (!!this.jSPlugin) {
  1510. return this.jSPlugin.JS_Resize(width,height);
  1511. } else {
  1512. throw new Error("Method not support");
  1513. }
  1514. }
  1515. EZUIPlayer.prototype.pause = function () {
  1516. this.opt.autoplay = false;
  1517. if (!!window['CKobject']) {
  1518. CKobject.getObjectById(this.flashId).videoPause();
  1519. } else if (!!this.video) {
  1520. if (!!this.JSmpeg) {
  1521. this.JSmpeg.pause();
  1522. } else {
  1523. this.video.pause();
  1524. }
  1525. } else if (!!this.jSPlugin) {
  1526. this.jSPlugin.JS_Pause(0).then(function () {
  1527. }, function () {
  1528. });
  1529. }
  1530. };
  1531. EZUIPlayer.prototype.load = function () {
  1532. if (!!window['CKobject']) {
  1533. // flash load
  1534. } else if (!!this.video) {
  1535. this.video.load();
  1536. }
  1537. };
  1538. // 开启电子放大
  1539. EZUIPlayer.prototype.enableZoom = function(iWind) {
  1540. if (!!this.jSPlugin) {
  1541. return this.jSPlugin.JS_EnableZoom(iWind || 0);
  1542. } else {
  1543. throw new Error("Method not support");
  1544. }
  1545. }
  1546. // 关闭电子放大
  1547. EZUIPlayer.prototype.closeZoom = function(iWind) {
  1548. if (!!this.jSPlugin) {
  1549. return this.jSPlugin.JS_DisableZoom(iWind || 0);
  1550. } else {
  1551. throw new Error("Method not support");
  1552. }
  1553. }
  1554. // iOS11手机HLS直播在m3u8响应时间过长后不继续请求的hack
  1555. 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;});}
  1556. function ltIE11() {var userAgent = navigator.userAgent; var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;if (isIE) {return true;} else {return false;}}
  1557. var EZUIKit = {
  1558. 'EZUIPlayer': EZUIPlayer,
  1559. };
  1560. // 兼容1.4 以下旧版本
  1561. // var EZUIPlayer = EZuikit.EZUIPlayer;
  1562. if (!noGlobal) {
  1563. window.EZUIKit = EZUIKit;
  1564. // 兼容1.4 以下旧版本
  1565. window.EZUIPlayer = EZUIPlayer;
  1566. }
  1567. return EZUIKit;
  1568. });