videoPlay.vue 4.9 KB

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