hik.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <!DOCTYPE html>
  2. <html lang="zn" xmlns:th="http://www.thymeleaf.org">
  3. <head>
  4. <th:block th:include="include :: header('直播管理')"/>
  5. <meta charset="UTF-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>H5playerVue</title>
  9. <link rel="stylesheet" href="../../../static/hik/static/css/antd.min.css" th:href="@{/hik/static/css/antd.min.css}">
  10. <style>
  11. body {
  12. padding: 8px 8px 32px;
  13. }
  14. #app {
  15. display: none;
  16. }
  17. .actions {
  18. padding-left: 8px;
  19. }
  20. .ant-form-item {
  21. margin-bottom: 8px
  22. }
  23. .ant-btn {
  24. margin-right: 2px;
  25. }
  26. .icon-wrapper {
  27. position: relative;
  28. padding-left: 20px;
  29. }
  30. .icon-wrapper .anticon {
  31. position: absolute;
  32. top: -2px;
  33. width: 16px;
  34. height: 16px;
  35. line-height: 1;
  36. font-size: 16px;
  37. left: 0;
  38. }
  39. ::-webkit-media-controls {
  40. display: none !important;
  41. }
  42. @media screen and (max-width: 991px) {
  43. #player {
  44. width: calc(100vw - 16px);
  45. height: calc((100vw - 16px) * 5 / 8);
  46. }
  47. }
  48. @media screen and (min-width: 992px) {
  49. #player {
  50. width: calc(50vw - 8px);
  51. height: calc((50vw - 8px) * 5 / 8);
  52. }
  53. }
  54. </style>
  55. </head>
  56. <body>
  57. <div>
  58. <div class="col-sm-12 search-collapse">
  59. <form id="formId">
  60. <div class="select-list">
  61. <ul>
  62. <li>
  63. <input type="hidden" name="cameraIndexCode" id="cameraIndexCode" th:value="${cameraIndexCode}"/>
  64. </li>
  65. </ul>
  66. </div>
  67. </form>
  68. </div>
  69. <div id="app">
  70. <a-locale-provider :locale="zh_CN">
  71. <a-row>
  72. <a-col :span="24" :md="12">
  73. <a-affix :offset-top="8">
  74. <div id="player"></div>
  75. </a-affix>
  76. </a-col>
  77. <a-col :span="24" :md="12">
  78. <div class="actions">
  79. <a-form :label-col="labelCol" :wrapper-col="wrapperCol" v-show="tabActive !== 'log'">
  80. <a-form-item>
  81. <a-row>
  82. <a-col :span="8">
  83. <a-button id="btn-realplay" @click="realplay">开始预览</a-button>
  84. <a-button id="btn-realplay-stop" @click="stopPlay">停止预览</a-button>
  85. </a-col>
  86. </a-row>
  87. </a-form-item>
  88. <a-form-item>
  89. <a-row>
  90. <a-col :span="8">
  91. <a-button id="btn-sound-open" @click="openSound">开启声音</a-button>
  92. <a-button id="btn-sound-close" @click="closeSound">关闭声音</a-button>
  93. </a-col>
  94. </a-row>
  95. </a-form-item>
  96. </a-form>
  97. </div>
  98. </a-col>
  99. </a-row>
  100. </a-locale-provider>
  101. </div>
  102. </div>
  103. <template id="play-log">
  104. <div></div>
  105. </template>
  106. <th:block th:include="include :: footer"/>
  107. <!-- 移动端调试 -->
  108. <!-- <script src="./static/js/vconsole.min.js"></script>
  109. <script>
  110. const vc = new VConsole()
  111. </script> -->
  112. <script src="../../../static/hik/static/js/moment.js" th:src="@{/hik/static/js/moment.js}"></script>
  113. <script src="../../../static/hik/static/js/vue.js" th:src="@{/hik/static/js/vue.js}"></script>
  114. <script src="../../../static/hik/static/js/antd.min.js" th:src="@{/hik/static/js/antd.min.js}"></script>
  115. <script src="../../../static/hik/static/js/antd-with-locales.min.js"
  116. th:src="@{/hik/static/js/antd-with-locales.min.js}"></script>
  117. <script src="../../../static/hik/h5player.min.js" th:src="@{/hik/h5player.min.js}"></script>
  118. <script th:inline="javascript">
  119. const {LocaleProvider, locales} = window.antd;
  120. moment.locale('../../../static/hik/static/js/zh-cn.js');
  121. const IS_MOVE_DEVICE = document.body.clientWidth < 992 // 是否移动设备
  122. const MSE_IS_SUPPORT = !!window.MediaSource // 是否支持mse
  123. getCameraPreviewURL()
  124. var prefix = ctx;
  125. function getCameraPreviewURL() {
  126. // alert(prefix+"ctx")
  127. $.ajax({
  128. url: ('' + prefix).split("undefined")[0] + "/system/hik/getCameraPreviewURL/" + cameraIndexCode.defaultValue,
  129. type: "GET",
  130. success: function (res) {
  131. let initUrl = res.data;
  132. initPage(initUrl)
  133. },
  134. error: function (err) {
  135. $.modal.msgSuccess("系统发生了错误, 请及时联系管理员进行处理! ")
  136. }
  137. })
  138. }
  139. function initPage(initUrl) {
  140. const app = new Vue({
  141. el: '#app',
  142. data() {
  143. return {
  144. zh_CN: locales.zh_CN,
  145. isMoveDevice: IS_MOVE_DEVICE,
  146. player: null,
  147. splitNum: IS_MOVE_DEVICE ? 1 : 2,
  148. mseSupport: MSE_IS_SUPPORT,
  149. tabActive: MSE_IS_SUPPORT ? 'mse' : 'decoder',
  150. labelCol: {span: 5},
  151. wrapperCol: {span: 18},
  152. urls: {
  153. // realplay: 'ws://218.62.80.146:559/openUrl/S8IunOU',
  154. realplay: initUrl,
  155. talk: 'wss://10.41.163.126:6014/proxy/10.41.163.126:559/EUrl/6gFx47S',
  156. playback: 'wss://10.41.163.126:6014/proxy/10.41.163.126:559/EUrl/6gFx47S'
  157. },
  158. playback: {
  159. startTime: '2025-01-10T00:00:00',
  160. endTime: '2025-01-12T23:59:59',
  161. valueFormat: moment.HTML5_FMT.DATETIME_LOCAL_SECONDS,
  162. seekStart: '2025-01-10T00:00:00',
  163. rate: ''
  164. },
  165. muted: true,
  166. volume: 70,
  167. volumeOnSvg: {
  168. template: '<svg t="1624453273744" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1421" width="200" height="200"><path d="M597.994667 138.005333q130.005333 28.010667 213.994667 132.992t84.010667 241.002667-84.010667 241.002667-213.994667 132.992l0-88q93.994667-28.010667 153.002667-106.005333t59.008-180.010667-59.008-180.010667-153.002667-106.005333l0-88zM704 512q0 120-106.005333 172.010667l0-344q106.005333 52.010667 106.005333 172.010667zM128 384l170.005333 0 213.994667-213.994667 0 684.010667-213.994667-213.994667-170.005333 0 0-256z" p-id="1422"></path></svg>'
  169. },
  170. volumeOffSvg: {
  171. template: '<svg t="1624453193279" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9147" width="200" height="200"><path d="M512 170.005333l0 180.010667-90.005333-90.005333zM181.994667 128l714.005333 714.005333-53.994667 53.994667-88-88q-74.005333 58.005333-156.010667 77.994667l0-88q50.005333-13.994667 96-50.005333l-181.994667-181.994667 0 288-213.994667-213.994667-170.005333 0 0-256 202.005333 0-202.005333-202.005333zM810.005333 512q0-101.994667-59.008-180.010667t-153.002667-106.005333l0-88q130.005333 28.010667 213.994667 132.992t84.010667 241.002667q0 96-44.010667 178.005333l-64-66.005333q21.994667-53.994667 21.994667-112zM704 512q0 18.005333-2.005333 26.005333l-104-104 0-93.994667q106.005333 52.010667 106.005333 172.010667z" p-id="9148"></path></svg>'
  172. }
  173. }
  174. },
  175. computed: {
  176. mode: function () {
  177. return this.tabActive === 'mse' ? 0 : 1
  178. }
  179. },
  180. methods: {
  181. init() {
  182. // 设置播放容器的宽高并监听窗口大小变化
  183. window.addEventListener('resize', () => {
  184. this.player.JS_Resize()
  185. })
  186. },
  187. createPlayer() {
  188. this.player = new window.JSPlugin({
  189. szId: 'player',
  190. szBasePath: "/hik/",
  191. iMaxSplit: 1,
  192. iCurrentSplit: IS_MOVE_DEVICE ? 1 : 2,
  193. openDebug: true,
  194. oStyle: {
  195. borderSelect: IS_MOVE_DEVICE ? '#000' : '#FFCC00',
  196. }
  197. })
  198. // 事件回调绑定
  199. this.player.JS_SetWindowControlCallback({
  200. windowEventSelect: function (iWndIndex) { //插件选中窗口回调
  201. console.log('windowSelect callback: ', iWndIndex);
  202. },
  203. pluginErrorHandler: function (iWndIndex, iErrorCode, oError) { //插件错误回调
  204. console.log('pluginError callback: ', iWndIndex, iErrorCode, oError);
  205. },
  206. windowEventOver: function (iWndIndex) { //鼠标移过回调
  207. //console.log(iWndIndex);
  208. },
  209. windowEventOut: function (iWndIndex) { //鼠标移出回调
  210. //console.log(iWndIndex);
  211. },
  212. windowEventUp: function (iWndIndex) { //鼠标mouseup事件回调
  213. //console.log(iWndIndex);
  214. },
  215. windowFullCcreenChange: function (bFull) { //全屏切换回调
  216. console.log('fullScreen callback: ', bFull);
  217. },
  218. firstFrameDisplay: function (iWndIndex, iWidth, iHeight) { //首帧显示回调
  219. console.log('firstFrame loaded callback: ', iWndIndex, iWidth, iHeight);
  220. },
  221. performanceLack: function () { //性能不足回调
  222. console.log('performanceLack callback: 性能不足回调');
  223. }
  224. });
  225. },
  226. wholeFullScreen() {
  227. this.player.JS_FullScreenDisplay(true).then(
  228. () => {
  229. console.log(`wholeFullScreen success`)
  230. },
  231. e => {
  232. console.error(e)
  233. }
  234. )
  235. },
  236. /* 预览&对讲 */
  237. realplay() {
  238. let {player, mode, urls} = this,
  239. index = player.currentWindowIndex,
  240. playURL = urls.realplay
  241. player.JS_Play(playURL, {playURL, mode}, index).then(
  242. () => {
  243. console.log('realplay success')
  244. },
  245. e => {
  246. console.error(e)
  247. }
  248. )
  249. },
  250. stopPlay() {
  251. let {player, mode, urls} = this,
  252. index = player.currentWindowIndex
  253. this.player.JS_Stop(index).then(
  254. () => {
  255. this.playback.rate = 0;
  256. console.log('stop realplay success')
  257. },
  258. e => {
  259. console.error(e)
  260. }
  261. )
  262. },
  263. /* 声音、抓图、录像 */
  264. openSound() {
  265. this.player.JS_OpenSound().then(
  266. () => {
  267. console.log('openSound success')
  268. this.muted = false
  269. },
  270. e => {
  271. console.error(e)
  272. }
  273. )
  274. },
  275. closeSound() {
  276. this.player.JS_CloseSound().then(
  277. () => {
  278. console.log('closeSound success')
  279. this.muted = true
  280. },
  281. e => {
  282. console.error(e)
  283. }
  284. )
  285. },
  286. capture() {
  287. let player = this.player,
  288. index = player.currentWindowIndex
  289. player.JS_CapturePicture(index, 'img', 'JPEG').then(
  290. () => {
  291. console.log('capture success')
  292. },
  293. e => {
  294. console.error(e)
  295. }
  296. )
  297. },
  298. },
  299. mounted() {
  300. this.$el.style.setProperty('display', 'block')
  301. this.init()
  302. this.createPlayer()
  303. this.realplay()
  304. }
  305. })
  306. }
  307. </script>
  308. </body>
  309. </html>