fullH5PlayerVideo.vue 7.7 KB

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