ezuikit.js 115 KB

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