videoPlay.vue 4.9 KB

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