H5PlayerVideoTime.vue 7.8 KB

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