videoPlay2.vue 5.0 KB

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