videoPlay.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view class="ezy-video-box course-video-box">
  3. <view ref="videoContent" id="video-play1" :playAuth="playAuth1"
  4. :change:playAuth="renderScript.receiveMsg" :videoId="videoId1" :change:videoId="renderScript.videoIdFun"
  5. :hideFlag="hideFlag1" :change:hideFlag="renderScript.hideFlagFun" :progressMarkers="progressMarkers1"
  6. :change:progressMarkers="renderScript.progressMarkersMsg" :seekTime="seekTime1"
  7. :change:seekTime="renderScript.seekTimeFun" class="ezy-video">
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import {MyRenderEventBus} from "./renderEvents"
  13. export default {
  14. name: "videoPlay",
  15. props: {
  16. cId: {
  17. type: String,
  18. },
  19. progressMarkers1: {
  20. type: Array,
  21. default: () => ([])
  22. },
  23. videoId1: {
  24. type: String,
  25. },
  26. playAuth1: {
  27. type: String,
  28. },
  29. seekTime1: {
  30. type: String
  31. },
  32. hideFlag1: {
  33. type: String
  34. }
  35. },
  36. data() {
  37. return {}
  38. },
  39. methods: {
  40. handleStop() {
  41. MyRenderEventBus.$emit('video-play1')
  42. }
  43. }
  44. }
  45. </script>
  46. <script module="renderScript" lang="renderjs">
  47. import {MyRenderEventBus} from "./renderEvents";
  48. export default {
  49. mounted() {
  50. MyRenderEventBus.$on(`video-play1`, this.stopPlayer)
  51. },
  52. Unmounted() {
  53. MyRenderEventBus.$ff(`video-play1`, this.stopPlayer)
  54. },
  55. data() {
  56. return {
  57. player: null,
  58. playAuth: '',
  59. videoId: '',
  60. progressMarkers: [],
  61. isFullScreen: false,
  62. seekTime: '',
  63. }
  64. },
  65. methods: {
  66. stopPlayer() {
  67. this.player && this.player.pause();
  68. },
  69. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  70. if (newValue) {
  71. this.playAuth = ''
  72. this.playAuth = newValue
  73. this.loadWebPlayerSDK()
  74. }
  75. },
  76. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  77. if (newValue) {
  78. this.videoId = ''
  79. this.videoId = newValue
  80. }
  81. },
  82. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  83. if (this.player) {
  84. this.player.pause()
  85. }
  86. },
  87. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  88. if (newValue) {
  89. this.progressMarkers = newValue
  90. }
  91. },
  92. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  93. if (newValue) {
  94. this.player.play()
  95. this.player.seek(newValue)
  96. }
  97. },
  98. playAli() {
  99. let that = this
  100. //配置播放器
  101. if (!this.playAuth) {
  102. return false;
  103. }
  104. var player = new Aliplayer({
  105. id: 'video-play1',
  106. "vid": this.videoId,
  107. "playauth": this.playAuth,
  108. extraInfo: {
  109. poster: 'noposter'
  110. },
  111. fullscreenEvents: {
  112. fullscreenChange: (isFull) => {
  113. this.isFullScreen = isFull
  114. }
  115. },
  116. "skinLayout": [{
  117. "name": "bigPlayButton",
  118. "align": "blabs",
  119. "x": 30,
  120. "y": 80
  121. },
  122. {
  123. "name": "H5Loading",
  124. "align": "cc"
  125. },
  126. {
  127. "name": "controlBar",
  128. "align": "blabs",
  129. "x": 0,
  130. "y": 0,
  131. "children": [{
  132. "name": "progress",
  133. "align": "blabs",
  134. "x": 0,
  135. "y": 44
  136. },
  137. {
  138. "name": "playButton",
  139. "align": "tl",
  140. "x": 15,
  141. "y": 12
  142. },
  143. {
  144. "name": "fullScreenButton",
  145. "align": "tr",
  146. "x": 10,
  147. "y": 12
  148. },
  149. {
  150. "name": "timeDisplay",
  151. "align": "tr",
  152. "x": 10,
  153. "y": 5
  154. }
  155. ]
  156. }
  157. ],
  158. "qualitySort": "asc",
  159. "format": "mp4",
  160. "mediaType": "video",
  161. "encryptType": 1,
  162. "progressMarkers": this.progressMarkers,
  163. "autoplay": false,
  164. "isLive": false,
  165. "rePlay": false,
  166. "playsinline": true,
  167. "preload": false,
  168. "controlBarVisibility": "hover",
  169. "useH5Prism": true
  170. }, function(player) {});
  171. this.player = player;
  172. player.on('canplay', function() {
  173. player.tag.play();
  174. });
  175. player.on('ended', function(data) {
  176. that.exitFullScreen();
  177. that.$ownerInstance.callMethod('playEnd', {
  178. data: 'end'
  179. })
  180. });
  181. },
  182. exitFullScreen() {
  183. if (document.exitFullscreen) {
  184. document.exitFullscreen(); // 标准方法
  185. } else if (document.mozCancelFullScreen) { // Firefox
  186. document.mozCancelFullScreen();
  187. } else if (document.webkitExitFullscreen) { // Chrome, Safari & Opera
  188. document.webkitExitFullscreen();
  189. } else if (document.msExitFullscreen) { // IE/Edge
  190. document.msExitFullscreen();
  191. }
  192. },
  193. loadWebPlayerSDK() {
  194. return new Promise((resolve, reject) => {
  195. const s_tag = document.createElement('script'); // 引入播放器js
  196. s_tag.type = 'text/javascript';
  197. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  198. s_tag.charset = 'utf-8';
  199. s_tag.onload = () => {
  200. // console.log(this.playAuth);
  201. this.playAli()
  202. resolve();
  203. }
  204. document.body.appendChild(s_tag);
  205. const l_tag = document.createElement('link'); // 引入播放器css
  206. l_tag.rel = 'stylesheet';
  207. l_tag.href =
  208. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  209. document.body.appendChild(l_tag);
  210. });
  211. },
  212. }
  213. }
  214. </script>