videoPlay.vue 5.1 KB

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