fullH5PlayerVideo.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div class="fullH5PlayerVideo">
  3. <div style="height:100%;width:100%;" :id="videoData.id+'full'" :ref="videoData.id"></div>
  4. <p class="full-failed-button" @click="outFullScreen"></p>
  5. </div>
  6. </template>
  7. <script>
  8. import { iotCameraGetPreviewURLs } from '@/api/index'
  9. export default {
  10. name: 'fullH5PlayerVideo',
  11. props: {
  12. fullVideoProps: {}
  13. },
  14. data() {
  15. return {
  16. fullScreenType:false,
  17. videoCover: localStorage.getItem('fileBrowseEnvironment') + localStorage.getItem('videoCover'),
  18. videoData: {},
  19. //全屏相关
  20. innerWidth:window.innerWidth,
  21. innerHeight:window.innerHeight,
  22. }
  23. },
  24. created() {
  25. },
  26. mounted() {
  27. this.iotCameraGetPreviewURLs();
  28. },
  29. methods: {
  30. iotCameraGetPreviewURLs(){
  31. let obj = {
  32. streamType:0,
  33. cameraIndexCode:this.fullVideoProps.cameraIndexCode,
  34. protocol: window.location.href.indexOf('https') !== -1 ? 'wss' : 'ws',
  35. }
  36. iotCameraGetPreviewURLs(obj).then(response => {
  37. this.$set(this, 'videoData', {
  38. id: 'video_' + this.generateRandomString(),
  39. url: response.data
  40. })
  41. this.$nextTick(() => {
  42. this.initH5Player(1)
  43. let type = response.data.indexOf('wss') !== -1?1:0;
  44. this.initPlayer(this.videoData.url, 0,type)
  45. })
  46. })
  47. },
  48. //全屏
  49. fullScreen() {
  50. let self = this;
  51. if(this.$parent.stopTime){
  52. this.$parent.stopTime(JSON.parse(JSON.stringify(this.fullVideoProps)));
  53. }else{
  54. this.myPlugin.JS_FullScreenDisplay(true).then(
  55. (res) => {
  56. // console.info('JS_FullScreenDisplay success');
  57. // do you want...
  58. },
  59. (err) => {
  60. // console.info('JS_FullScreenDisplay failed');
  61. // do you want...
  62. }
  63. );
  64. self.$set(self,'fullScreenType',true);
  65. }
  66. },
  67. //退出全屏
  68. outFullScreen() {
  69. this.$parent.outFullScreen();
  70. },
  71. initH5Player(split) {
  72. this.myPlugin = new window.JSPlugin({
  73. szId: this.videoData.id+'full', //需要英文字母开头,唯一性,必填
  74. szBasePath: '/h5player/', // 必填,与h5player.min.js的引用目录一致 填写的是pulblic下的路径!!!
  75. bSupporDoubleClickFull: false,//是否支持双击全屏,默认true
  76. openDebug: true,
  77. oStyle: {
  78. borderSelect: '#000'
  79. },
  80. // 当容器div#play_window有固定宽高时,可不传iWidth和iHeight,窗口大小将自适应容器宽高
  81. // iWidth: this.innerWidth,
  82. // iHeight: this.innerHeight,
  83. // 分屏播放,默认最大分屏4*4
  84. iMaxSplit: split,
  85. iCurrentSplit: split
  86. })
  87. let iWndNum = 1;
  88. let InterruptTime = 5;
  89. this.myPlugin.JS_SetInterruptTime(iWndNum, InterruptTime).then(
  90. () => {
  91. // console.info('JS_SetInterruptTime success');
  92. // do you want...
  93. },
  94. (err) => {
  95. // console.info('JS_SetInterruptTime failed');
  96. // do you want...
  97. }
  98. );
  99. // 事件回调绑定
  100. this.myPlugin.JS_SetWindowControlCallback({
  101. windowEventSelect: function (iWndIndex) { //插件选中窗口回调
  102. // console.log('windowSelect callback: ', iWndIndex)
  103. },
  104. pluginErrorHandler: function (iWndIndex, iErrorCode, oError) { //插件错误回调
  105. // console.log('pluginError callback: ', iWndIndex, iErrorCode, oError)
  106. },
  107. windowEventOver: function (iWndIndex) { //鼠标移过回调
  108. //console.log(iWndIndex);
  109. },
  110. windowEventOut: function (iWndIndex) { //鼠标移出回调
  111. //console.log(iWndIndex);
  112. },
  113. windowEventUp: function (iWndIndex) { //鼠标mouseup事件回调
  114. //console.log(iWndIndex);
  115. },
  116. windowFullCcreenChange: function (bFull) { //全屏切换回调
  117. // console.log('fullScreen callback: ', bFull)
  118. },
  119. firstFrameDisplay: function (iWndIndex, iWidth, iHeight) { //首帧显示回调
  120. // console.log('firstFrame loaded callback: ', iWndIndex, iWidth, iHeight)
  121. },
  122. performanceLack: function () { //性能不足回调
  123. // console.log('performanceLack callback: ')
  124. }
  125. })
  126. },
  127. initPlayer(url, index, type) {
  128. this.myPlugin.JS_Play(url,
  129. {
  130. playURL: url, // 流媒体播放时必传
  131. mode: type?type:0 // 解码类型:0=普通模式; 1=高级模式 默认为0
  132. // ...
  133. },
  134. index //当前窗口下标
  135. ).then(
  136. () => {
  137. // console.info('JS_Play success')
  138. // do you want...
  139. //开启声音
  140. this.myPlugin.JS_OpenSound().then(
  141. () => {
  142. console.log('openSound success')
  143. },
  144. e => {
  145. console.error('声音开启失败',e)
  146. }
  147. )
  148. },
  149. (err) => {
  150. // console.info('JS_Play failed:', err)
  151. // do you want...
  152. }
  153. )
  154. },
  155. //生成随机ID
  156. generateRandomString() {
  157. let chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
  158. let randomString = ''
  159. for (let i = 0; i < 24; i++) {
  160. let randomIndex = Math.floor(Math.random() * chars.length)
  161. randomString += chars.charAt(randomIndex)
  162. }
  163. return randomString
  164. },
  165. videoOff() {
  166. this.myPlugin.JS_StopRealPlayAll().then(
  167. () => {
  168. // console.info('JS_StopRealPlayAll success')
  169. // do you want...
  170. },
  171. (err) => {
  172. // console.info('JS_StopRealPlayAll failed')
  173. // do you want...
  174. }
  175. )
  176. }
  177. },
  178. beforeDestroy() {
  179. let self = this
  180. self.videoOff()
  181. }
  182. }
  183. </script>
  184. <style scoped lang="scss">
  185. .fullH5PlayerVideo {
  186. margin: 0;
  187. padding: 0;
  188. display: inline-block;
  189. z-index:11;
  190. height: 100%;
  191. width:100%;
  192. position: fixed;
  193. top:0;
  194. left:0;
  195. * {
  196. margin: 0;
  197. padding: 0;
  198. }
  199. /*position: relative;*/
  200. .full-failed-button {
  201. background: url("../../assets/icon_1.png");
  202. background-size: 100%;
  203. position: fixed;
  204. font-size: 20px;
  205. height: 50px;
  206. width: 50px;
  207. line-height: 30px;
  208. text-align: center;
  209. top: 40px;
  210. right: 40px;
  211. z-index: 12;
  212. cursor: pointer;
  213. }
  214. }
  215. </style>