|
205 | 205 | var getRealUrl = this.getRealUrl(playParams); |
206 | 206 | /**是否自动播放 */ |
207 | 207 | if (isPromise(getRealUrl)) { |
208 | | - getRealUrl.then(function () { |
| 208 | + getRealUrl.then(function (data) { |
209 | 209 | var initDecoder = _this.initDecoder(playParams); |
210 | 210 | if (isPromise(initDecoder) && (playParams.autoplay !== false)) { |
211 | | - initDecoder.then(function () { |
212 | | - _this.play({ handleError: playParams.handleError }); |
| 211 | + initDecoder.then(function (data) { |
| 212 | + _this.play({ handleError: playParams.handleError, handleSuccess: playParams.handleSuccess }); |
213 | 213 | }) |
214 | 214 | } |
215 | 215 | }) |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | }; |
| 340 | + // 日志 |
| 341 | + EZUIPlayer.prototype.log = function (msg, className) { |
| 342 | + this.emit('log', msg, className); |
| 343 | + }; |
340 | 344 |
|
341 | 345 | EZUIPlayer.prototype.getRealUrl = function (playParams) { |
342 | 346 | var _this = this; |
|
358 | 362 | // _this.opt.currentSource = realUrl; |
359 | 363 | resolve(realUrl); |
360 | 364 | } else { |
361 | | - resolve('get realURL error') |
| 365 | + // 将错误信息捕获到用户自定义错误回调中 |
| 366 | + if (playParams && playParams.handleError) { |
| 367 | + playParams.handleError(data); |
| 368 | + } |
| 369 | + reject(JSON.stringify(data)); |
362 | 370 | throw new Error('获取播放token失败'); |
363 | 371 | } |
364 | 372 | } |
365 | 373 | var nodeError = function (error) { |
366 | | - console.log("getdecoder url from api error", error); |
367 | | - throw new Error('获取播放token失败'); |
| 374 | + // 将错误信息捕获到用户自定义错误回调中 |
| 375 | + if(playParams && playParams.handleError){ |
| 376 | + playParams.handleError(error); |
| 377 | + } |
| 378 | + reject(JSON.stringify(error)) |
| 379 | + throw new Error('获取播放token失败', 'error'); |
368 | 380 | } |
369 | 381 | // 向API请求真实地址 |
370 | 382 | var apiUrl = apiDomain + "/api/lapp/live/url/ezopen"; |
|
399 | 411 | } |
400 | 412 | request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError); |
401 | 413 | } else { |
402 | | - resolve('get realURL error') |
| 414 | + // 将错误信息捕获到用户自定义错误回调中 |
| 415 | + if (playParams && playParams.handleError) { |
| 416 | + playParams.handleError(data); |
| 417 | + } |
| 418 | + reject(JSON.stringify(data), 'error') |
403 | 419 | //throw new Error('获取播放设备信息失败'); |
404 | 420 | } |
405 | 421 | /**参数容错处理 end*/ |
406 | 422 | } |
407 | 423 | var apiError = function (error) { |
408 | | - console.log("getdecoder url from api error", error); |
409 | | - resolve('get realURL error') |
| 424 | + // 将错误信息捕获到用户自定义错误回调中 |
| 425 | + if (playParams && playParams.handleError) { |
| 426 | + playParams.handleError(error); |
| 427 | + } |
| 428 | + reject(JSON.stringify(error)) |
410 | 429 | //throw new Error('获取播放设备信息失败'); |
411 | 430 | } |
412 | 431 | var isHttp = 'false'; |
|
436 | 455 | }); |
437 | 456 | var getRealUrlPromiseObj = Promise.all(promiseTaskList) |
438 | 457 | .then(function (result) { |
| 458 | + // 获取真实地址成功后,赋值到opt属性中 |
439 | 459 | _this.opt.sources = result; |
440 | 460 | _this.opt.currentSource = result[0]; |
441 | 461 | }) |
442 | 462 | .catch(function (err) { |
| 463 | + _this.log("获取真实地址错误" + JSON.stringify(err), 'error') |
443 | 464 | }) |
444 | 465 | return getRealUrlPromiseObj; |
445 | 466 | } else { |
446 | 467 | if (!this.opt.currentSource) { |
447 | | - this.log('未找到合适的播放URL'); |
| 468 | + this.log('未找到合适的播放URL', 'error'); |
448 | 469 | return; |
449 | 470 | } |
450 | 471 | var me = this; |
|
512 | 533 | that.video.load(); |
513 | 534 | that.tryPlay(data.data); |
514 | 535 | } else { |
515 | | - console.log("平台获取播放地址错误") |
516 | 536 | that.log('data: ' + JSON.stringify(data)); |
517 | 537 | throw new Error(data.msg); |
518 | 538 | return; |
|
669 | 689 | this.hls = hls; |
670 | 690 | }; |
671 | 691 |
|
672 | | - // 日志 |
673 | | - EZUIPlayer.prototype.log = function (msg) { |
674 | | - this.emit('log', msg); |
675 | | - }; |
676 | 692 |
|
677 | 693 | // 初始化ckplayer |
678 | 694 | EZUIPlayer.prototype.initCKPlayer = function (url) { |
|
904 | 920 | if (!params || typeof params.index === 'undefined') { |
905 | 921 | _this.opt.sources.forEach(function (item, index) { |
906 | 922 | _this.jSPlugin.JS_Play(getPlayParams(item).websocketConnectUrl, { playURL: getPlayParams(item).websocketStreamingParam }, index).then(function () { |
907 | | - console.log("realplay success", index); |
| 923 | + _this.log('播放成功,当前播放第' + (index + 1) + '路'); |
908 | 924 | // 默认开启声音 |
909 | 925 | // 默认开启第一路声音 |
910 | 926 | if (index === 0) { |
911 | | - _this.log("默认开启第一路声音"); |
| 927 | + _this.log("默认开启第1路声音"); |
912 | 928 | setTimeout(() => { |
913 | 929 | _this.jSPlugin.JS_OpenSound(0); |
914 | 930 | }, 100) |
915 | 931 | } |
| 932 | + // 播放成功回调 |
916 | 933 | if (params && params.handleSuccess) { |
917 | 934 | params.handleSuccess(); |
918 | 935 | } |
919 | 936 | }, function (err) { |
920 | | - console.log("realplay failed", err.oError); |
| 937 | + _this.log('播放失败' + JSON.stringify(err), 'error'); |
921 | 938 | if (params && params.handleError) { |
922 | 939 | var errorInfo = JSON.parse(_this.errorCode).find(function (item) { return item.detailCode.substr(-4) == err.oError.errorCode }) |
923 | 940 | params.handleError({ retcode: err.oError.errorCode, msg: errorInfo ? errorInfo.description : '其他错误' }); |
|
927 | 944 | } else { |
928 | 945 | params.index.forEach(function (item, index) { |
929 | 946 | _this.jSPlugin.JS_Play(getPlayParams(_this.opt.sources[item]).websocketConnectUrl, { playURL: getPlayParams(_this.opt.sources[item]).websocketStreamingParam }, item).then(function () { |
930 | | - console.log("realplay success", index); |
| 947 | + _this.log('播放成功,当前播放第' + (index + 1) + '路') |
931 | 948 | // 默认开启第一路声音 |
932 | 949 | if (index === 0) { |
933 | 950 | _this.log("默认开启第一路声音"); |
934 | | - console.log("默认开启第一路声音") |
935 | 951 | setTimeout(() => { |
936 | 952 | _this.jSPlugin.JS_OpenSound(0); |
937 | 953 | }, 100) |
|
940 | 956 | params.handleSuccess(); |
941 | 957 | } |
942 | 958 | }, function (err) { |
943 | | - console.log("realplay failed", err.oError); |
| 959 | + _this.log('播放失败' + JSON.stringify(err), 'error'); |
944 | 960 | if (params && params.handleError) { |
945 | 961 | var errInfo = err.oError;// 包装错误码 |
946 | 962 | params.handleError(errInfo); |
|
977 | 993 | _this.jSPlugin.JS_Resize(playParams.width || 600, playParams.height || 400); |
978 | 994 | } |
979 | 995 | _this.log("初始化解码器----完成"); |
980 | | - _this.log("开始设置秘钥"); |
981 | 996 | var validateCode = _this.opt.validateCode; |
982 | 997 | if (validateCode) { |
| 998 | + _this.log("开始设置秘钥"); |
983 | 999 | _this.jSPlugin.JS_SetSecretKey(0, validateCode); |
984 | 1000 | } |
985 | 1001 | resolve('200 OK') |
|
0 commit comments