h52dgp.html 21 KB

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