videoPlay2.vue 4.9 KB

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