webLive.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
  5. <title>ImouPlayer</title>
  6. <script src="./imouplayer.js"></script>
  7. <style>
  8. * {
  9. /* font-family: PingFaangSC-Regular, Arial, 'Microsoft YaHei'; */
  10. margin: 0;
  11. padding: 0
  12. }
  13. button {
  14. display: block;
  15. width: 120px;
  16. line-height: 30px;
  17. border: 1px solid #409eff;
  18. background-color: #409eff;
  19. color: #fff;
  20. border-radius: 5px;
  21. cursor: pointer;
  22. margin-left: 73px;
  23. }
  24. .wrap {
  25. width: 80%;
  26. max-width: 600px;
  27. margin: 0 auto;
  28. }
  29. .icon {
  30. display: inline-block;
  31. width: 20px;
  32. line-height: 20px;
  33. text-align: center;
  34. background-color: #c1c1c1;
  35. border-radius: 50%;
  36. color: #fff;
  37. font-style: normal;
  38. cursor: pointer;
  39. position: relative;
  40. transition: background-color 0.3s ease;
  41. }
  42. .tip {
  43. display: block;
  44. text-align: right;
  45. font-size: 12px;
  46. color: #999;
  47. }
  48. @media only screen and (max-width: 768px) {
  49. html,
  50. body {
  51. padding: 0;
  52. margin: 0;
  53. }
  54. .wrap {
  55. width: 100%;
  56. }
  57. p {
  58. padding: 0 20px;
  59. }
  60. }
  61. </style>
  62. <script defer="defer" src="imouplayer.js"></script>
  63. </head>
  64. <body>
  65. <div id="app"></div>
  66. <div id="error"></div>
  67. <script>
  68. window.onload = function() {
  69. let urlParams = getUrlParams(window.location.search);
  70. console.log(urlParams);
  71. let player;
  72. let playerOption = {
  73. isEdit: false,
  74. url: urlParams.url || 'imou://open.lechange.com/6H0BXXXXXXX3D90/0/1?streamId=1',
  75. kitToken: urlParams.kitToken || 'Kt_3baccxxxxxxxxxxxxxxxxxxxxxa183e',
  76. // 是否自动播放
  77. autoplay: true,
  78. // 是否显示控制台
  79. controls: true,
  80. // 是否开启静音
  81. automute: true,
  82. themeData: [{
  83. area: 'header',
  84. fontColor: '#F18D00',
  85. backgroundColor: '#FFFFFF',
  86. activeButtonColor: '#0E72FF',
  87. buttonList: [{
  88. show: true,
  89. id: 'deviceName',
  90. name: '设备名称',
  91. position: 'left',
  92. }, {
  93. show: true,
  94. id: 'channalId',
  95. name: '设备通道',
  96. position: 'left',
  97. }, {
  98. show: true,
  99. id: 'cloudVideo',
  100. name: '云录像',
  101. position: 'right',
  102. }, {
  103. show: true,
  104. id: 'localVideo',
  105. name: '本地录像',
  106. position: 'right',
  107. }]
  108. }, {
  109. area: 'footer',
  110. fontColor: '#F18D00',
  111. backgroundColor: '#FFFFFF',
  112. activeButtonColor: '#0E72FF',
  113. buttonList: [{
  114. show: true,
  115. id: 'play',
  116. name: '播放',
  117. position: 'left',
  118. }, {
  119. show: true,
  120. id: 'mute',
  121. name: '音量控制',
  122. position: 'left',
  123. }, {
  124. show: true,
  125. id: 'talk',
  126. name: '语音对讲',
  127. position: 'left',
  128. }, {
  129. show: true,
  130. id: 'capture',
  131. name: '截图',
  132. position: 'left',
  133. }, {
  134. show: true,
  135. id: 'definition',
  136. name: '清晰度控制',
  137. position: 'right',
  138. }, {
  139. show: true,
  140. id: 'PTZ',
  141. name: '云台控制',
  142. position: 'right',
  143. }, {
  144. show: true,
  145. id: 'webExpend',
  146. name: '网页全屏',
  147. position: 'right',
  148. }, {
  149. show: true,
  150. id: 'extend',
  151. name: '全屏控制',
  152. position: 'right',
  153. }]
  154. }],
  155. };
  156. // 填写默认值
  157. function $(selector) {
  158. return document.querySelector(selector);
  159. }
  160. document.body.addEventListener('touchmove', function(e) {
  161. e.preventDefault();
  162. console.log('禁止拖动');
  163. }, {
  164. passive: false
  165. });
  166. function getUrlParams(data) {
  167. let paramsList = {};
  168. let paramsString = data.slice(1);
  169. let list
  170. if (paramsString.indexOf('%7C') != -1) {
  171. list = paramsString.split('%7C');
  172. } else {
  173. list = paramsString.split('|');
  174. }
  175. list.forEach(item => {
  176. let list = item.split('=');
  177. key = list.shift();
  178. value = list.join('=');
  179. paramsList[key] = value;
  180. })
  181. return paramsList
  182. }
  183. function initLive() {
  184. if (player) {
  185. player.destroy()
  186. }
  187. player = new ImouPlayer('#app');
  188. // const url = $('#url').value.trim();
  189. // const kitToken = $('#kitToken').value.trim();
  190. const url = playerOption.url;
  191. const kitToken = playerOption.kitToken;
  192. const urlArr = [];
  193. url.split('%').forEach(function(item, index) {
  194. const obj = {
  195. url: item,
  196. kitToken: kitToken,
  197. talk: {
  198. success: (msg) => {
  199. console.log('type', msg)
  200. },
  201. failed: (msg) => {
  202. console.log('failed', msg)
  203. }
  204. }
  205. };
  206. urlArr.push(obj)
  207. });
  208. // const width = window.innerWidth;
  209. const width = checkMobile() ? $('body').clientWidth : window.innerWidth;
  210. console.log(width);
  211. const height = checkMobile() ? parseInt(width * 9 / 16) : window.innerHeight;
  212. // const height = window.innerHeight;
  213. const params = {
  214. src: urlArr,
  215. width: width,
  216. height: height,
  217. isEdit: playerOption.isEdit,
  218. autoplay: playerOption.autoplay,
  219. controls: playerOption.controls,
  220. automute: playerOption.automute,
  221. themeData: playerOption.themeData
  222. };
  223. // console.log(params, '11111111111111111111111111');
  224. player.setup(params);
  225. };
  226. function checkMobile() {
  227. if (!navigator) return false;
  228. const reg = /(iPhone|iPod|Android|ios|SymbianOS)/i;
  229. return reg.test(navigator.userAgent);
  230. }
  231. (function() {
  232. initLive();
  233. })();
  234. // $('#init').onclick = function() {
  235. // initLive();
  236. // }
  237. // $('#startTalk').onclick = function() {
  238. // player.startTalk()
  239. // }
  240. // $('#stopTalk').onclick = function() {
  241. // player.stopTalk()
  242. // }
  243. };
  244. </script>
  245. </body>
  246. </html>