H5PlayerVideo.vue 6.4 KB

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