videoPlay2.vue 4.8 KB

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