h52dgp.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. <!DOCTYPE html>
  2. <html lang=zh-CN>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport"
  6. content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  7. <title>监控详情页</title>
  8. <link href="https://unpkg.com/video.js@7.10.2/dist/video-js.min.css" rel="stylesheet" />
  9. <link rel="stylesheet" href="./font/iconfont.css" />
  10. <style type="text/css">
  11. body {
  12. margin: 0;
  13. background-color: #f3f3f3;
  14. }
  15. span.vjs-control-text {
  16. display: none;
  17. }
  18. /* iframe {
  19. width: 375px;
  20. height: 667px;
  21. background-color: #fff;
  22. box-sizing: content-box;
  23. border: none;
  24. } */
  25. .btn-box {
  26. margin-top: 20px;
  27. display: flex;
  28. flex-direction: row;
  29. justify-content: space-around;
  30. align-items: center;
  31. }
  32. .btn-container {
  33. position: relative;
  34. }
  35. .videoBtnPlay {
  36. position: absolute;
  37. height: 100px;
  38. width: 100px;
  39. top: 50%;
  40. left: 50%;
  41. transform: translate(-50%, -50%);
  42. }
  43. .more,
  44. .less {
  45. flex: 1
  46. }
  47. img {
  48. width: 100%;
  49. }
  50. .direc {
  51. width: 150px;
  52. height: 150px;
  53. background: url('https://s3.hnyfwlw.com/webstaticimg/bigdata_app/image/monitor/1.png');
  54. background-size: 100% auto;
  55. background-repeat: no-repeat;
  56. position: relative;
  57. display: flex;
  58. justify-content: center;
  59. align-items: center;
  60. }
  61. .direc div {
  62. width: 50px;
  63. height: 50px;
  64. position: absolute;
  65. }
  66. .photo {
  67. font-size: 30px;
  68. color: #4ec467;
  69. padding: 16px;
  70. }
  71. .top {
  72. top: 0;
  73. left: 50px
  74. }
  75. .bottom {
  76. bottom: 0;
  77. left: 50px
  78. }
  79. .left {
  80. left: 0;
  81. top: 50px
  82. }
  83. .right {
  84. right: 0;
  85. top: 50px
  86. }
  87. #box {
  88. height: 300px;
  89. width: 100%;
  90. background: #000;
  91. overflow: hidden;
  92. }
  93. #dialog {
  94. display: none;
  95. min-width: 200px;
  96. line-height: 80px;
  97. background: rgba(0, 0, 0, .8);
  98. color: #fff;
  99. text-align: center;
  100. position: absolute;
  101. left: 50%;
  102. margin-left: -100px;
  103. border-radius: 4px;
  104. z-index: 999;
  105. top: 50%;
  106. margin-top: -40px;
  107. }
  108. .imgBtn {
  109. position: absolute;
  110. width: 100%;
  111. padding: 10px;
  112. bottom: 0;
  113. left: 0;
  114. text-align: center;
  115. color: #338cd9;
  116. font-size: 16px;
  117. box-sizing: border-box;
  118. display: flex;
  119. justify-content: center;
  120. gap: 16px;
  121. }
  122. .imgBtn div {
  123. /* padding: 0 16px; */
  124. }
  125. .imgBtn img {
  126. display: inline-block;
  127. width: 20px;
  128. height: 20px;
  129. vertical-align: middle;
  130. margin-right: 2px;
  131. margin-bottom: 3px;
  132. }
  133. .imgBtnDgp {
  134. display: none;
  135. }
  136. </style>
  137. </head>
  138. <body>
  139. <div class="btn-container">
  140. <div id="box"> </div>
  141. <div class="videoBtnPlay">
  142. <img src="https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/img/wxplayer.png" />
  143. </div>
  144. </div>
  145. <div id="dialog">
  146. </div>
  147. <div class="btn-box">
  148. <div class="more" ontouchstart="_configCamera('move', 8)" ontouchend="_stopConfigCamera()">
  149. <image src="https://s3.hnyfwlw.com/webstaticimg/bigdata_app/image/monitor/3.png" mode="widthFix">
  150. </image>
  151. </div>
  152. <div class="direc">
  153. <div class="top" ontouchstart="_configCamera('move', 0)" ontouchend="_stopConfigCamera()">
  154. </div>
  155. <div class="bottom" ontouchstart="_configCamera('move', 1)" ontouchend="_stopConfigCamera()">
  156. </div>
  157. <p class="photo yficonfont icon-paizhao-xianxing" ontouchstart="_configCamera('takephoto', '')">
  158. </p>
  159. <div class="left" ontouchstart="_configCamera('move', 2)" ontouchend="_stopConfigCamera()">
  160. </div>
  161. <div class="right" ontouchstart="_configCamera('move', 3)" ontouchend="_stopConfigCamera()">
  162. </div>
  163. </div>
  164. <div class="less" ontouchstart="_configCamera('move', 9)" ontouchend="_stopConfigCamera()">
  165. <image src="https://s3.hnyfwlw.com/webstaticimg/bigdata_app/image/monitor/2.png" mode="widthFix">
  166. </image>
  167. </div>
  168. </div>
  169. <div class="imgBtn">
  170. <div class="imgBtnCamrea"> <img src="https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/img/img_icon.png" />查看图片</div>
  171. <div class="imgBtnDgp"><img src="https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/img/img_icon.png" />查看光谱图片</div>
  172. </div>
  173. </body>
  174. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  175. <!-- 微信 JS-SDK 如果不需要兼容小程序,则无需引用此 JS 文件。 -->
  176. <!-- <script type="text/javascript" src="//res.wx.qq.com/open/js/jweixin-1.4.0.js"></script> -->
  177. <!-- uni 的 SDK -->
  178. <script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>
  179. <script src="https://unpkg.com/video.js@7.10.2/dist/video.min.js"></script>
  180. <script type="module">
  181. import Player from './videoPlayer/videoPlay-js.js'
  182. // 检测HLS支持
  183. function checkHLSSupport() {
  184. const video = document.createElement('video');
  185. return video.canPlayType('application/vnd.apple.mpegurl') !== '' ||
  186. video.canPlayType('application/x-mpegURL') !== '';
  187. }
  188. // 加载HLS.js库(如果需要)
  189. function loadHLSJS() {
  190. return new Promise((resolve, reject) => {
  191. if (window.Hls) {
  192. resolve();
  193. return;
  194. }
  195. const script = document.createElement('script');
  196. script.src = 'https://cdn.jsdelivr.net/npm/hls.js@latest';
  197. script.onload = () => {
  198. console.log('HLS.js加载完成');
  199. resolve();
  200. };
  201. script.onerror = reject;
  202. document.head.appendChild(script);
  203. });
  204. }
  205. let player = null
  206. let stopTimer = 0
  207. // 更安全的URL参数解析
  208. function getUrlParam(name) {
  209. const urlParams = new URLSearchParams(window.location.search)
  210. return urlParams.get(name) || ''
  211. }
  212. var device_id = getUrlParam('device_id')
  213. var accessToken = getUrlParam('accessToken')
  214. var videoType = getUrlParam('videoType')
  215. var token = accessToken
  216. console.log('解析结果:', { device_id, accessToken, videoType })
  217. console.log('视频类型检查:', videoType, videoType === 'dgp')
  218. // 通用错误处理函数
  219. function showError(message, duration = 3000) {
  220. $('#dialog').html(message).stop().show(500).delay(duration).hide(500);
  221. $('.videoBtnPlay').show();
  222. }
  223. // 安全的JSON解析
  224. function safeParseJSON(str) {
  225. try {
  226. return JSON.parse(str);
  227. } catch(e) {
  228. console.warn('JSON解析失败,尝试eval:', e);
  229. try {
  230. return eval('(' + str + ')');
  231. } catch(e2) {
  232. console.error('数据解析完全失败:', e2);
  233. return null;
  234. }
  235. }
  236. }
  237. // 验证API响应
  238. function validateAPIResponse(res, apiName = 'API') {
  239. console.log(`${apiName}响应:`, res);
  240. if (!res) {
  241. console.error(`${apiName}响应为空`);
  242. return { valid: false, error: '服务器无响应' };
  243. }
  244. if (res.message && res.message !== '') {
  245. console.error(`${apiName}返回错误:`, res.message);
  246. return { valid: false, error: res.message };
  247. }
  248. if (!res.data) {
  249. console.error(`${apiName}返回数据为空`);
  250. return { valid: false, error: '返回数据为空' };
  251. }
  252. return { valid: true, data: res.data };
  253. }
  254. // 获取可用的视频源
  255. function getAvailableVideoSource(data, preferredType = 'hls') {
  256. const sources = {
  257. hls: data.hls,
  258. hlsHd: data.hlsHd,
  259. rtmp: data.rtmp,
  260. rtsp: data.rtsp
  261. };
  262. console.log('可用视频源:', sources);
  263. // 优先使用指定类型
  264. if (sources[preferredType] && sources[preferredType] !== 'undefined' && sources[preferredType] !== '') {
  265. return { source: sources[preferredType], type: preferredType };
  266. }
  267. // 按优先级查找可用源
  268. const priority = ['hls', 'hlsHd', 'rtmp', 'rtsp'];
  269. for (const type of priority) {
  270. if (sources[type] && sources[type] !== 'undefined' && sources[type] !== '') {
  271. return { source: sources[type], type: type };
  272. }
  273. }
  274. return { source: null, type: null };
  275. }
  276. // 检查设备状态
  277. function checkDeviceStatus() {
  278. console.log('检查设备状态...');
  279. $('#dialog').html('检查设备状态...').stop().show();
  280. return $.ajax({
  281. type: "POST",
  282. url: "http://47.110.79.22:9000/api/api_gateway?method=device.device_manage.get_device_info",
  283. data: {
  284. device_id: device_id,
  285. token: token
  286. },
  287. timeout: 5000
  288. }).then((res) => {
  289. console.log('设备状态响应:', res);
  290. if (res && res.message === '' && res.data) {
  291. const deviceInfo = typeof res.data === 'string' ? safeParseJSON(res.data) : res.data;
  292. console.log('设备信息:', deviceInfo);
  293. return deviceInfo;
  294. } else {
  295. throw new Error(res.message || '获取设备信息失败');
  296. }
  297. }).catch((error) => {
  298. console.error('设备状态检查失败:', error);
  299. showError('设备状态检查失败: ' + (error.message || '网络错误'));
  300. throw error;
  301. });
  302. }
  303. window._configCamera = configCamera;
  304. window._stopConfigCamera = stopConfigCamera;
  305. window._postPic = postPic;
  306. // 确保DOM加载完成后再执行jQuery操作
  307. $(document).ready(function() {
  308. // 初始化HLS支持
  309. if (!checkHLSSupport()) {
  310. console.log('浏览器不支持原生HLS,加载HLS.js');
  311. loadHLSJS().catch(e => {
  312. console.error('HLS.js加载失败:', e);
  313. });
  314. }
  315. if (videoType == 'dgp') {
  316. $('.imgBtnDgp').show()
  317. } else {
  318. $('.imgBtnDgp').hide()
  319. }
  320. $('.photo').click(() => {
  321. // 拍照功能
  322. })
  323. })
  324. function configCamera(ctrl, movenum) {
  325. if (ctrl == "takephoto") {
  326. if (player) {
  327. // 云联的拍照特殊处理
  328. player.screenshot('yunlianPlayer')
  329. } else {
  330. $('#dialog').html('拍照指令正在下发,请等待...').stop().show(50)
  331. let url = "http://47.110.79.22:9000/api/api_gateway?method=camera.camera_manage.camera_takephoto"
  332. if (videoType == 'dgp') {
  333. url = "http://47.110.79.22:9000/api/api_gateway?method=camera.camera_manage.multi_camera_takephoto"
  334. }
  335. $.ajax({
  336. type: "POST",
  337. url: url,
  338. data: {
  339. device_id: device_id,
  340. token
  341. }
  342. }).then((res) => {
  343. if (res.data == true) {
  344. $('#dialog').html('拍照成功').stop().show(500).delay(1000).hide(500)
  345. } else {
  346. $('#dialog').html(res.message).stop().show(500).delay(1000).hide(500)
  347. }
  348. });
  349. }
  350. } else {
  351. let url = "http://47.110.79.22:9000/api/api_gateway?method=camera.camera_manage.ctrl_camera"
  352. let postData = {
  353. device_id: device_id,
  354. token
  355. }
  356. if (videoType == 'dgp') {
  357. url = "http://47.110.79.22:9000/api/api_gateway?method=camera.camera_manage.multi_ctrl_camera"
  358. postData.ctrl = movenum
  359. } else {
  360. postData.ctrl = ctrl
  361. postData.movenum = movenum
  362. }
  363. //上下左右、放大、缩小
  364. $.ajax({
  365. type: "POST",
  366. url: url,
  367. data: postData
  368. }).then((res) => {
  369. $('#dialog').html('指令下发成功,请等待...').stop().show(500).delay(3000).hide(500)
  370. })
  371. }
  372. }
  373. function stopConfigCamera() {
  374. if (videoType == 'dgp') {
  375. if(stopTimer) clearTimeout(stopTimer)
  376. stopTimer = setTimeout(()=>{
  377. $.ajax({
  378. type: "POST",
  379. url: "http://47.110.79.22:9000/api/api_gateway?method=camera.camera_manage.mulit_stop_move",
  380. data: {
  381. device_id: device_id,
  382. token
  383. },
  384. });
  385. },3000)
  386. } else {
  387. $.ajax({
  388. type: "POST",
  389. url: "http://47.110.79.22:9000/api/api_gateway?method=camera.camera_manage.ctrl_camera",
  390. data: {
  391. device_id: device_id,
  392. ctrl: "stop",
  393. token
  394. },
  395. });
  396. }
  397. }
  398. function postPic(file) {
  399. let form = new FormData()
  400. form.append('img_file', file)
  401. form.append('device_id', device_id)
  402. form.append('token', token)
  403. $.ajax({
  404. type: "POST",
  405. url: "http://47.110.79.22:9000/api/api_gateway?method=camera.camera_manage.save_camera_photo",
  406. contentType: false,
  407. processData: false,
  408. data: form
  409. }).then((res) => {
  410. if (res.message == '') {
  411. $('#dialog').html('拍照成功').stop().show(500).delay(1500).hide(500)
  412. } else {
  413. $('#dialog').html(res.data.message).stop().show(500).delay(1500).hide(500)
  414. }
  415. });
  416. }
  417. async function initYunlianPlayer(videoURL) {
  418. var playHtml =
  419. `<div id="yunlianPlayer" style="width: 100%;height: 300px;overflow: hidden;"></div>`;
  420. $("#box").html(playHtml)
  421. player = new Player(['yunlianPlayer'], {
  422. playFileOver: () => {
  423. console.log('播放结束')
  424. },
  425. playError: (id, e) => {
  426. console.log('播放错误', id, e)
  427. },
  428. talkStart: () => {
  429. console.log('对讲开始')
  430. },
  431. runtimeInitializedCallBack: () => {
  432. console.log('播放器初始化完成')
  433. },
  434. captureCallback: (id, data) => {
  435. // console.log('截图返回的数据', data.buffer)
  436. const blob = new Blob([data], {
  437. type: 'image/jpeg'
  438. })
  439. _postPic(blob)
  440. }
  441. })
  442. await player.init()
  443. setTimeout(() => {
  444. player.play('yunlianPlayer', {
  445. streamURL: videoURL,
  446. channelId: '0',
  447. bitStream: '0',
  448. isLive: true
  449. })
  450. }, 1000)
  451. }
  452. $('.videoBtnPlay').click(function() {
  453. $('.videoBtnPlay').hide()
  454. console.log(videoType,'videoTypevideoType')
  455. // 显示加载提示
  456. $('#dialog').html('正在获取视频流...').stop().show();
  457. // 先检查设备状态(可选,如果API支持的话)
  458. // checkDeviceStatus().then(() => {
  459. if (videoType == 'dgp') {
  460. $.ajax({
  461. type: "POST",
  462. url: "http://47.110.79.22:9000/api/api_gateway?method=camera.camera_manage.multi_addr_camera",
  463. data: {
  464. device_id: device_id,
  465. token
  466. },
  467. timeout: 15000 // 15秒超时
  468. }).then((res) => {
  469. $('#dialog').hide(); // 隐藏加载提示
  470. const validation = validateAPIResponse(res, 'DGP视频流API');
  471. if (!validation.valid) {
  472. showError(validation.error);
  473. return;
  474. }
  475. let data = validation.data;
  476. if (typeof data == 'string') {
  477. data = safeParseJSON(data);
  478. if (!data) {
  479. showError('DGP数据解析失败');
  480. return;
  481. }
  482. }
  483. console.log('DGP解析后的数据:', data);
  484. // 获取可用的视频源(DGP优先使用rtmp)
  485. const videoSource = getAvailableVideoSource(data, 'rtmp');
  486. if (!videoSource.source) {
  487. console.error('DGP没有找到可用的视频源');
  488. showError('设备可能离线或未配置视频流,请检查设备状态');
  489. return;
  490. }
  491. console.log(`使用${videoSource.type}视频源:`, videoSource.source);
  492. console.log(`使用${videoSource.type}视频源:`, videoSource.source);
  493. const hlsHdSrc = videoSource.source;
  494. var playHtml =
  495. `<video id="myPlayer" poster='' controls playsInline webkit-playsinline style="width:100%; height:100%;"></video>`;
  496. $("#box").html(playHtml)
  497. var myVideo = videojs(`myPlayer`, {
  498. controls: true,
  499. autoplay: false,
  500. preload: 'metadata',
  501. sources: [{
  502. type: videoSource.type === 'rtmp' ? 'rtmp/flv' : 'application/x-mpegURL',
  503. src: hlsHdSrc,
  504. }],
  505. html5: {
  506. hls: {
  507. enableLowInitialPlaylist: true,
  508. smoothQualityChange: true,
  509. overrideNative: true
  510. }
  511. }
  512. }, function onPlayerReady() {
  513. console.log('DGP播放器准备完成');
  514. // 延迟播放,确保源加载完成
  515. setTimeout(() => {
  516. myVideo.play().catch(e => {
  517. console.error('DGP播放失败:', e);
  518. showError('DGP视频播放失败: ' + e.message);
  519. });
  520. }, 500);
  521. });
  522. // 添加错误处理
  523. myVideo.on('error', function(e) {
  524. console.error('DGP Video.js错误:', e, myVideo.error());
  525. const error = myVideo.error();
  526. let errorMsg = 'DGP视频播放出错';
  527. if (error) {
  528. switch(error.code) {
  529. case 1:
  530. errorMsg = 'DGP视频加载被中止';
  531. break;
  532. case 2:
  533. errorMsg = 'DGP网络错误导致视频下载失败';
  534. break;
  535. case 3:
  536. errorMsg = 'DGP视频解码失败';
  537. break;
  538. case 4:
  539. errorMsg = 'DGP视频格式不支持或视频源无效';
  540. break;
  541. default:
  542. errorMsg = 'DGP未知播放错误';
  543. }
  544. }
  545. showError(errorMsg);
  546. });
  547. myVideo.on('play', function() {
  548. console.log('DGP开始播放')
  549. });
  550. myVideo.on('loadstart', function() {
  551. console.log('DGP开始加载视频');
  552. });
  553. myVideo.on('canplay', function() {
  554. console.log('DGP视频可以播放');
  555. });
  556. })
  557. } else {
  558. $.ajax({
  559. type: "POST",
  560. // url: "http://47.110.79.22:9000/api/api_gateway?method=camera.camera_manage.multi_addr_camera",
  561. url: "http://192.168.1.107:8000/api/api_gateway?method=camera.camera_manage.multi_addr_camera",
  562. data: {
  563. device_id: device_id,
  564. token
  565. // device_id: 'FA8690323-1',
  566. // token: localStorage.getItem('session_key')
  567. }
  568. }).then((res) => {
  569. console.log('API响应:', res);
  570. if (res && res.message == '') {
  571. var data = null
  572. if (typeof res.data == 'string') {
  573. data = safeParseJSON(res.data);
  574. } else {
  575. data = res.data;
  576. }
  577. if (!data) {
  578. showError('数据解析失败');
  579. return;
  580. }
  581. console.log('解析后的数据:', data);
  582. console.log('数据字段检查:', {
  583. type_id: data.type_id,
  584. hls: data.hls,
  585. hlsHd: data.hlsHd,
  586. rtsp: data.rtsp,
  587. rtmp: data.rtmp
  588. });
  589. if (data.type_id == 2) {
  590. // 大华云联
  591. if (!data.rtsp || data.rtsp === 'undefined' || data.rtsp === '') {
  592. console.error('RTSP视频源无效:', data.rtsp);
  593. showError('RTSP视频源获取失败,请检查设备配置');
  594. return;
  595. }
  596. initYunlianPlayer(data.rtsp)
  597. } else {
  598. let hlsHdSrc = data.type_id == 0 ? data.hls : data.hlsHd;
  599. console.log('选择的视频源字段:', data.type_id == 0 ? 'hls' : 'hlsHd');
  600. console.log('视频源值:', hlsHdSrc);
  601. // 如果主要源无效,尝试备用源
  602. if (!hlsHdSrc || hlsHdSrc === 'undefined' || hlsHdSrc === '') {
  603. console.warn('主要视频源无效,尝试备用源');
  604. hlsHdSrc = data.hls || data.hlsHd || data.rtmp || data.rtsp;
  605. console.log('备用视频源:', hlsHdSrc);
  606. }
  607. // 验证视频源
  608. if (!hlsHdSrc || hlsHdSrc === 'undefined' || hlsHdSrc === '') {
  609. console.error('所有视频源都无效:', {
  610. hls: data.hls,
  611. hlsHd: data.hlsHd,
  612. rtmp: data.rtmp,
  613. rtsp: data.rtsp
  614. });
  615. showError('视频源获取失败,请检查设备是否在线或联系管理员');
  616. return;
  617. }
  618. console.log('视频源:', hlsHdSrc);
  619. var playHtml =
  620. `<video id="myPlayer" poster='' controls playsInline webkit-playsinline style="width:100%; height:100%;"></video>`;
  621. $("#box").html(playHtml)
  622. var myVideo = videojs(`myPlayer`, {
  623. controls: true,
  624. autoplay: false,
  625. preload: 'metadata',
  626. sources: [{
  627. type: 'application/x-mpegURL',
  628. src: hlsHdSrc,
  629. }],
  630. html5: {
  631. hls: {
  632. enableLowInitialPlaylist: true,
  633. smoothQualityChange: true,
  634. overrideNative: true
  635. }
  636. }
  637. }, function onPlayerReady() {
  638. console.log('播放器准备完成');
  639. setTimeout(() => {
  640. myVideo.play().catch(e => {
  641. console.error('播放失败:', e);
  642. $('#dialog').html('视频播放失败: ' + e.message).stop().show(500).delay(3000).hide(500);
  643. $('.videoBtnPlay').show();
  644. });
  645. }, 500);
  646. });
  647. // 添加错误处理
  648. myVideo.on('error', function(e) {
  649. console.error('Video.js错误:', e, myVideo.error());
  650. const error = myVideo.error();
  651. let errorMsg = '视频播放出错';
  652. if (error) {
  653. switch(error.code) {
  654. case 1:
  655. errorMsg = '视频加载被中止';
  656. break;
  657. case 2:
  658. errorMsg = '网络错误导致视频下载失败';
  659. break;
  660. case 3:
  661. errorMsg = '视频解码失败';
  662. break;
  663. case 4:
  664. errorMsg = '视频格式不支持或视频源无效';
  665. break;
  666. default:
  667. errorMsg = '未知播放错误';
  668. }
  669. }
  670. $('#dialog').html(errorMsg).stop().show(500).delay(3000).hide(500);
  671. $('.videoBtnPlay').show();
  672. });
  673. myVideo.on('play', function() {
  674. console.log('开始播放')
  675. });
  676. myVideo.on('loadstart', function() {
  677. console.log('开始加载视频');
  678. });
  679. myVideo.on('canplay', function() {
  680. console.log('视频可以播放');
  681. });
  682. }
  683. } else {
  684. alert(res.message)
  685. }
  686. })
  687. }
  688. })
  689. document.addEventListener('UniAppJSBridgeReady', function() {
  690. $('.imgBtnCamrea').click(function() {
  691. // if (player) {
  692. // player.close('yunlianPlayer')
  693. // player = null
  694. // }
  695. uni.navigateTo({
  696. url: '/pages/monitor/imagelist?id=' + device_id
  697. })
  698. })
  699. $('.imgBtnDgp').click(function() {
  700. // if (player) {
  701. // player.close('yunlianPlayer')
  702. // player = null
  703. // }
  704. uni.navigateTo({
  705. url: '/pages/monitor/dgpImagelist?id=' + device_id
  706. })
  707. })
  708. });
  709. </script>
  710. </html>