demo.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>H5playerVue</title>
  8. <link rel="stylesheet" href="./static/css/antd.min.css">
  9. <style>
  10. body {
  11. padding: 8px 8px 32px;
  12. }
  13. #app {
  14. display: none;
  15. }
  16. .actions {
  17. padding-left: 8px;
  18. }
  19. .ant-form-item {
  20. margin-bottom: 8px
  21. }
  22. .ant-btn {
  23. margin-right: 2px;
  24. }
  25. .icon-wrapper {
  26. position: relative;
  27. padding-left: 20px;
  28. }
  29. .icon-wrapper .anticon {
  30. position: absolute;
  31. top: -2px;
  32. width: 16px;
  33. height: 16px;
  34. line-height: 1;
  35. font-size: 16px;
  36. left: 0;
  37. }
  38. ::-webkit-media-controls {
  39. display: none !important;
  40. }
  41. @media screen and (max-width: 991px) {
  42. #player {
  43. width: calc(100vw - 16px);
  44. height: calc((100vw - 16px) * 5 / 8);
  45. }
  46. }
  47. @media screen and (min-width: 992px) {
  48. #player {
  49. width: calc(50vw - 8px);
  50. height: calc((50vw - 8px) * 5 / 8);
  51. }
  52. }
  53. </style>
  54. </head>
  55. <body>
  56. <div id="app">
  57. <a-locale-provider :locale="zh_CN">
  58. <a-row>
  59. <a-col :span="24" :md="12">
  60. <a-affix :offset-top="8">
  61. <div id="player"></div>
  62. </a-affix>
  63. <a-form-item>
  64. 分屏
  65. <a-radio-group v-model="splitNum" @change="arrangeWindow">
  66. <a-radio-button :value="1">1x1</a-radio-button>
  67. <a-radio-button :value="2">2x2</a-radio-button>
  68. <a-radio-button :value="3" v-show="!isMoveDevice">3x3</a-radio-button>
  69. <a-radio-button :value="4" v-show="!isMoveDevice">4x4</a-radio-button>
  70. </a-radio-group>
  71. <a-button @click="wholeFullScreen" v-show="!isMoveDevice">整体全屏</a-button>
  72. </a-form-item>
  73. </a-col>
  74. <a-col :span="24" :md="12">
  75. <div class="actions">
  76. <a-tabs v-model="tabActive">
  77. <a-tab-pane key="mse" tab="普通模式" :disabled="!mseSupport"></a-tab-pane>
  78. <a-tab-pane key="decoder" tab="高级模式"></a-tab-pane>
  79. <!-- <a-tab-pane key="log" tab="日志"></a-tab-pane> -->
  80. </a-tabs>
  81. <a-form :label-col="labelCol" :wrapper-col="wrapperCol" v-show="tabActive !== 'log'">
  82. <a-form-item label="预览URL">
  83. <a-input v-model="urls.realplay"></a-input>
  84. </a-form-item>
  85. <a-form-item label="对讲URL">
  86. <a-input v-model="urls.talk"></a-input>
  87. </a-form-item>
  88. <a-form-item label="预览&对讲">
  89. <a-button id="btn-realplay" @click="realplay">开始预览</a-button>
  90. <a-button id="btn-realplay-stop" @click="stopPlay">停止预览</a-button>
  91. <a-button id="btn-talk-start" @click="talkStart">开始对讲</a-button>
  92. <a-button id="btn-talk-stop" @click="talkStop">停止对讲</a-button>
  93. <a-button id="btn-stopall" @click="stopAllPlay">停止全部窗口</a-button>
  94. </a-form-item>
  95. <a-form-item label="回放URL">
  96. <a-input v-model="urls.playback"></a-input>
  97. <br>
  98. <a-date-picker show-time placeholder="开始时间" format="YYYY-MM-DD HH:mm:ss" v-model="playback.startTime" :value-format="playback.valueFormat">
  99. </a-date-picker>
  100. <a-date-picker show-time placeholder="结束时间" format="YYYY-MM-DD HH:mm:ss" v-model="playback.endTime" :value-format="playback.valueFormat">
  101. </a-date-picker>
  102. </a-form-item>
  103. <a-form-item label="回放">
  104. <a-button id="btn-playback" @click="playbackStart">开始回放</a-button>
  105. <a-button id="btn-playback-pause" @click="playbackPause">暂停</a-button>
  106. <a-button id="btn-playback-sesume" @click="playbackResume">恢复</a-button>
  107. <a-button id="btn-playback-stop" @click="stopPlay">停止回放</a-button>
  108. <br>
  109. <a-row>
  110. <a-col :span="16">
  111. <a-button id="btn-playback-slow" @click="playbackSlow">慢放</a-button>
  112. <a-button id="btn-playback-fast" @click="playbackFast">快放</a-button>
  113. <a-button id="btn-playback-one" @click="frameForward" v-show="tabActive === 'decoder'">单帧</a-button>
  114. <br>
  115. <a-date-picker show-time placeholder="开始时间" format="YYYY-MM-DD HH:mm:ss" v-model="playback.seekStart" :value-format="playback.valueFormat">
  116. </a-date-picker>
  117. &nbsp;<a-button @click="seekTo">定位</a-button>
  118. </a-col>
  119. <a-col :span="8">
  120. <a-statistic title="当前播放速度" :value="playback.rate"></a-statistic>
  121. </a-col>
  122. </a-row>
  123. </a-form-item>
  124. <a-form-item label="声音">
  125. <a-row>
  126. <a-col :span="10">
  127. <a-button id="btn-sound-open" @click="openSound">开启</a-button>
  128. <a-button id="btn-sound-close" @click="closeSound">关闭</a-button>
  129. </a-col>
  130. <a-col :span="12">
  131. <div class="icon-wrapper">
  132. <a-icon v-if="muted" :component="volumeOffSvg"></a-icon>
  133. <a-icon v-else :component="volumeOnSvg"></a-icon>
  134. <a-slider v-model="volume" :default-value="50" :disabled="muted" @change="setVolume"></a-slider>
  135. </div>
  136. </a-col>
  137. </a-row>
  138. </a-form-item>
  139. <a-form-item label="抓图&录像">
  140. <a-button id="btn-capture-jpeg" @click="capture()">抓图</a-button>
  141. <br>
  142. <a-button id="btn-record-mp4" @click="recordStart('MP4')">录制MP4</a-button>
  143. <a-button id="btn-record-ps" @click="recordStart('PS')">录制PS</a-button>
  144. <a-button id="btn-record-save" @click="recordStop">停止录制并保存文件</a-button>
  145. </a-form-item>
  146. <a-form-item label="视频信息&OSD时间">
  147. <a-button id="btn-video-info" @click="getvideoInfo">获取视频信息</a-button>
  148. <a-button id="btn-ose-time" @click="getOSDTime">获取OSD时间</a-button>
  149. </a-form-item>
  150. <a-form-item label="电子放大&智能信息" v-show="tabActive === 'decoder'">
  151. <a-button id="btn-enlarge-open" @click="enlarge">开启电子放大</a-button>
  152. <a-button id="btn-enlarge-close" @click="enlargeClose">关闭电子放大</a-button>
  153. <a-button id="btn-intellect-open" @click="intellectTrigger(true)">开启智能信息</a-button>
  154. <a-button id="btn-intellect-close" @click="intellectTrigger(false)">关闭智能信息</a-button>
  155. </a-form-item>
  156. </a-form>
  157. </div>
  158. </a-col>
  159. </a-row>
  160. </a-locale-provider>
  161. </div>
  162. <template id="play-log">
  163. <div></div>
  164. </template>
  165. <!-- 移动端调试 -->
  166. <!-- <script src="./static/js/vconsole.min.js"></script>
  167. <script>
  168. const vc = new VConsole()
  169. </script> -->
  170. <script src="./static/js/moment.js"></script>
  171. <script src="./static/js/vue.js"></script>
  172. <script src="./static/js/antd.min.js"></script>
  173. <script src="./static/js/antd-with-locales.min.js"></script>
  174. <script src="./h5player.min.js"></script>
  175. <script>
  176. const { LocaleProvider, locales } = window.antd
  177. moment.locale('./static/js/zh-cn.js')
  178. const IS_MOVE_DEVICE = document.body.clientWidth < 992 // 是否移动设备
  179. const MSE_IS_SUPPORT = !!window.MediaSource // 是否支持mse
  180. // const Log = Vue.component('log', {
  181. // template: '#play-log',
  182. // data() {
  183. // return {
  184. // }
  185. // },
  186. // methods: {
  187. // }
  188. // })
  189. const app = new Vue({
  190. el: '#app',
  191. // components: { Log },
  192. data() {
  193. return {
  194. zh_CN: locales.zh_CN,
  195. isMoveDevice: IS_MOVE_DEVICE,
  196. player: null,
  197. splitNum: IS_MOVE_DEVICE ? 1 : 2,
  198. mseSupport: MSE_IS_SUPPORT,
  199. tabActive: MSE_IS_SUPPORT ? 'mse' : 'decoder',
  200. labelCol: { span: 5 },
  201. wrapperCol: { span: 18 },
  202. urls: {
  203. realplay: 'ws://10.19.147.22:559/EUrl/q2jQie4',
  204. talk: 'wss://10.41.163.126:6014/proxy/10.41.163.126:559/EUrl/6gFx47S',
  205. playback: 'wss://10.41.163.126:6014/proxy/10.41.163.126:559/EUrl/6gFx47S'
  206. },
  207. playback: {
  208. startTime: '2021-07-26T00:00:00',
  209. endTime: '2021-07-26T23:59:59',
  210. valueFormat: moment.HTML5_FMT.DATETIME_LOCAL_SECONDS,
  211. seekStart: '2021-07-26T12:00:00',
  212. rate: ''
  213. },
  214. muted: true,
  215. volume: 50,
  216. volumeOnSvg: {
  217. 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>'
  218. },
  219. volumeOffSvg: {
  220. 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>'
  221. }
  222. }
  223. },
  224. computed: {
  225. mode: function () {
  226. return this.tabActive === 'mse' ? 0 : 1
  227. }
  228. },
  229. methods: {
  230. init() {
  231. // 设置播放容器的宽高并监听窗口大小变化
  232. window.addEventListener('resize', () => {
  233. this.player.JS_Resize()
  234. })
  235. },
  236. createPlayer() {
  237. this.player = new window.JSPlugin({
  238. szId: 'player',
  239. szBasePath: "./",
  240. iMaxSplit: 4,
  241. iCurrentSplit: IS_MOVE_DEVICE ? 1 : 2,
  242. openDebug: true,
  243. oStyle: {
  244. borderSelect: IS_MOVE_DEVICE ? '#000' : '#FFCC00',
  245. }
  246. })
  247. console.log({
  248. szId: 'player',
  249. szBasePath: "./",
  250. iMaxSplit: 4,
  251. iCurrentSplit: IS_MOVE_DEVICE ? 1 : 2,
  252. openDebug: true,
  253. oStyle: {
  254. borderSelect: IS_MOVE_DEVICE ? '#000' : '#FFCC00',
  255. }
  256. })
  257. // 事件回调绑定
  258. this.player.JS_SetWindowControlCallback({
  259. windowEventSelect: function (iWndIndex) { //插件选中窗口回调
  260. console.log('windowSelect callback: ', iWndIndex);
  261. },
  262. pluginErrorHandler: function (iWndIndex, iErrorCode, oError) { //插件错误回调
  263. console.log('pluginError callback: ', iWndIndex, iErrorCode, oError);
  264. },
  265. windowEventOver: function (iWndIndex) { //鼠标移过回调
  266. //console.log(iWndIndex);
  267. },
  268. windowEventOut: function (iWndIndex) { //鼠标移出回调
  269. //console.log(iWndIndex);
  270. },
  271. windowEventUp: function (iWndIndex) { //鼠标mouseup事件回调
  272. //console.log(iWndIndex);
  273. },
  274. windowFullCcreenChange: function (bFull) { //全屏切换回调
  275. console.log('fullScreen callback: ', bFull);
  276. },
  277. firstFrameDisplay: function (iWndIndex, iWidth, iHeight) { //首帧显示回调
  278. console.log('firstFrame loaded callback: ', iWndIndex, iWidth, iHeight);
  279. },
  280. performanceLack: function () { //性能不足回调
  281. console.log('performanceLack callback: ');
  282. }
  283. });
  284. },
  285. arrangeWindow() {
  286. let splitNum = this.splitNum
  287. this.player.JS_ArrangeWindow(splitNum).then(
  288. () => { console.log(`arrangeWindow to ${splitNum}x${splitNum} success`) },
  289. e => { console.error(e) }
  290. )
  291. },
  292. wholeFullScreen() {
  293. this.player.JS_FullScreenDisplay(true).then(
  294. () => { console.log(`wholeFullScreen success`) },
  295. e => { console.error(e) }
  296. )
  297. },
  298. /* 预览&对讲 */
  299. realplay() {
  300. let { player, mode, urls } = this,
  301. index = player.currentWindowIndex,
  302. playURL = urls.realplay
  303. console.log(mode, playURL, index)
  304. player.JS_Play(playURL, { playURL, mode }, index).then(
  305. () => { console.log('realplay success') },
  306. e => { console.error(e) }
  307. )
  308. },
  309. stopPlay() {
  310. let { player, mode, urls } = this,
  311. index = player.currentWindowIndex
  312. this.player.JS_Stop(index).then(
  313. () => { this.playback.rate = 0; console.log('stop realplay success') },
  314. e => { console.error(e) }
  315. )
  316. },
  317. talkStart() {
  318. let url = this.urls.talk
  319. this.player.JS_SetConnectTimeOut(0, 1000)
  320. this.player.JS_StartTalk(url).then(
  321. () => { console.log('talkStart success') },
  322. e => { console.error(e) }
  323. )
  324. },
  325. talkStop() {
  326. this.player.JS_StopTalk().then(
  327. () => { console.log('talkStop success') },
  328. e => { console.error(e) }
  329. )
  330. },
  331. stopAllPlay() {
  332. this.player.JS_StopRealPlayAll().then(
  333. () => { this.playback.rate = 0; console.log('stopAllPlay success') },
  334. e => { console.error(e) }
  335. )
  336. },
  337. /* 回放 */
  338. playbackStart() {
  339. let { player, mode, urls, playback } = this,
  340. index = player.currentWindowIndex,
  341. playURL = urls.playback,
  342. { startTime, endTime } = playback
  343. startTime += 'Z'
  344. endTime += 'Z'
  345. player.JS_Play(playURL, { playURL, mode }, index, startTime, endTime).then(
  346. () => {
  347. console.log('playbackStart success')
  348. this.playback.rate = 1
  349. },
  350. e => { console.error(e) }
  351. )
  352. },
  353. playbackPause() {
  354. this.player.JS_Pause().then(
  355. () => { console.log('playbackPause success') },
  356. e => { console.error(e) }
  357. )
  358. },
  359. playbackResume() {
  360. this.player.JS_Resume().then(
  361. () => { console.log('playbackResume success') },
  362. e => { console.error(e) }
  363. )
  364. },
  365. seekTo() {
  366. let { seekStart, endTime } = this.playback
  367. seekStart += 'Z'
  368. endTime += 'Z'
  369. this.player.JS_Seek(this.player.currentWindowIndex, seekStart, endTime).then(
  370. () => { console.log('seekTo success') },
  371. e => { console.error(e) }
  372. )
  373. },
  374. playbackSlow() {
  375. this.player.JS_Slow().then(
  376. rate => {
  377. this.playback.rate = rate
  378. },
  379. e => { console.error(e) }
  380. )
  381. },
  382. playbackFast() {
  383. this.player.JS_Fast().then(
  384. rate => {
  385. this.playback.rate = rate
  386. },
  387. e => { console.error(e) }
  388. )
  389. },
  390. frameForward() {
  391. this.player.JS_FrameForward(this.player.currentWindowIndex).then(
  392. () => { this.playback.rate = 1; console.log('frameForward success') },
  393. e => { console.error(e) }
  394. )
  395. },
  396. /* 声音、抓图、录像 */
  397. openSound() {
  398. this.player.JS_OpenSound().then(
  399. () => {
  400. console.log('openSound success')
  401. this.muted = false
  402. },
  403. e => { console.error(e) }
  404. )
  405. },
  406. closeSound() {
  407. this.player.JS_CloseSound().then(
  408. () => {
  409. console.log('closeSound success')
  410. this.muted = true
  411. },
  412. e => { console.error(e) }
  413. )
  414. },
  415. setVolume(value) {
  416. let player = this.player,
  417. index = player.currentWindowIndex
  418. this.player.JS_SetVolume(index, value).then(
  419. () => {
  420. console.log('setVolume success', value)
  421. },
  422. e => { console.error(e) }
  423. )
  424. },
  425. capture() {
  426. let player = this.player,
  427. index = player.currentWindowIndex
  428. player.JS_CapturePicture(index, 'img', 'JPEG').then(
  429. () => { console.log('capture success') },
  430. e => { console.error(e) }
  431. )
  432. },
  433. recordStart(type) {
  434. const codeMap = { MP4: 5, PS: 2 }
  435. let player = this.player,
  436. index = player.currentWindowIndex,
  437. fileName = `${moment().format('YYYYMMDDHHmm')}.mp4`
  438. typeCode = codeMap[type]
  439. player.JS_StartSaveEx(index, fileName, typeCode).then(
  440. () => { console.log('record start ...') },
  441. e => { console.error(e) }
  442. )
  443. },
  444. recordStop() {
  445. let player = this.player
  446. index = player.currentWindowIndex
  447. player.JS_StopSave(index).then(
  448. () => { console.log('record stoped, saving ...') },
  449. e => { console.error(e) }
  450. )
  451. },
  452. /* 电子放大、智能信息 */
  453. enlarge() {
  454. let player = this.player,
  455. index = player.currentWindowIndex
  456. player.JS_EnableZoom(index).then(
  457. () => { console.log('enlarge start..., select range...') },
  458. e => { console.error(e) }
  459. )
  460. },
  461. enlargeClose() {
  462. let player = this.player,
  463. index = player.currentWindowIndex
  464. player.JS_DisableZoom(index).then(
  465. () => { console.log('enlargeClose success') },
  466. e => { console.error(e) }
  467. )
  468. },
  469. intellectTrigger(openFlag) {
  470. let player = this.player,
  471. index = player.currentWindowIndex
  472. let result = player.JS_RenderALLPrivateData(index, openFlag)
  473. console.log(`${openFlag ? 'open' : 'close'} intellect ${result === 1 ? 'success' : 'failed'}`)
  474. },
  475. getvideoInfo() {
  476. let player = this.player,
  477. index = player.currentWindowIndex
  478. player.JS_GetVideoInfo(index).then(function (videoInfo) {
  479. console.log("videoInfo:", videoInfo);
  480. });
  481. },
  482. getOSDTime() {
  483. let player = this.player,
  484. index = player.currentWindowIndex
  485. player.JS_GetOSDTime(index).then(function (time) {
  486. console.log("osdTime:", new Date(time));
  487. });
  488. }
  489. },
  490. mounted() {
  491. this.$el.style.setProperty('display', 'block')
  492. this.init()
  493. this.createPlayer()
  494. }
  495. })
  496. </script>
  497. </body>
  498. </html>