questionJiexi.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view>
  3. <uni-popup ref="popupRef" :animation="false" :is-mask-click="false"
  4. mask-background-color="rgba(255, 255, 255, 0.6);" class="ezy-popup-width-all">
  5. <view class="ezy-dajx-page">
  6. <view class="icon-title-navBar-box">
  7. <view @click="handleBack" class="nav-bar-icon"></view>
  8. <view class="nav-bar-title">单元测试</view>
  9. </view>
  10. <view class="shiti-frame-box">
  11. <view class="dajx-content-box">
  12. <!-- 思路分析 -->
  13. <view class="slfx-title"></view>
  14. <view class="slfx-content"> {{data.answer}}</view>
  15. <!-- <view class="slfx-content"> {{data.answer}}</view> -->
  16. <!-- 视频讲解 -->
  17. <view class="spjj-title"></view>
  18. <view class="spjj-video-box">
  19. <!-- 这里放视频 ↓ -->
  20. <view class="spjj-video" ref="videoContent" id="wgy-player-test" :playAuth="playAuth"
  21. :change:playAuth="renderScript.receiveMsg"
  22. :seekTime="seekTime"
  23. :change:seekTime="renderScript.seekTimeFun">
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </uni-popup>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. onLoad,
  35. onReady
  36. } from '@dcloudio/uni-app';
  37. import {
  38. videoPolicy,
  39. getVideoAuth,
  40. getVideoRefresh
  41. } from "@/api/shipin.js"
  42. export default {
  43. data() {
  44. return {
  45. pageData: null, //上个页面获取的视频参数(视频id)
  46. playAuth: "", //播放凭证
  47. progressMarkers: [],
  48. videoId: "", //阿里云视频id
  49. seekTime: '',
  50. data:{}
  51. }
  52. },
  53. methods: {
  54. showPopup(item){
  55. this.data = item;
  56. //this.videoId = item.jiangjie
  57. this.videoId = 'b997f16cb9cb474cb93526cff77d8801'
  58. // this.progressMarkers = item.progressMarkers
  59. this.getLive(); //获取播放凭证
  60. this.$refs.popupRef.open()
  61. },
  62. handleBack(item){
  63. this.$refs.popupRef.close()
  64. },
  65. getLive() {
  66. let req = {
  67. videoId: this.videoId
  68. }
  69. getVideoAuth(req).then(res => {
  70. this.playAuth = res.data
  71. })
  72. },
  73. markersClick(data) {
  74. console.log(data)
  75. this.seekTime = data.offset
  76. },
  77. },
  78. created() {
  79. // console.log("getLive")
  80. // this.getLive(); //获取播放凭证
  81. },
  82. }
  83. </script>
  84. <script module="renderScript" lang="renderjs">
  85. export default {
  86. mounted() {
  87. console.log("renderScript1")
  88. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  89. this.loadWebPlayerSDK()
  90. },
  91. data() {
  92. return {
  93. player: null,
  94. playAuth: '',
  95. progressMarkers: [],
  96. seekTime: ''
  97. }
  98. },
  99. methods: {
  100. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  101. if (newValue) {
  102. this.playAuth = newValue
  103. this.playAli()
  104. }
  105. },
  106. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  107. if (newValue) {
  108. this.progressMarkers = newValue
  109. }
  110. },
  111. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  112. if (newValue) {
  113. console.log(newValue, 'newValuenewValuenewValuenewValuenewValue')
  114. console.log(this.player.getStatus(), 'newValuenewValuenewValuenewValuenewValue')
  115. switch (this.player.getStatus()) {
  116. case 'init':
  117. break;
  118. case 'ready':
  119. break;
  120. case 'loading':
  121. this.player.play()
  122. this.player.seek(newValue)
  123. break;
  124. case 'play':
  125. this.player.seek(newValue)
  126. break;
  127. case 'pause':
  128. this.player.play()
  129. this.player.seek(newValue)
  130. break;
  131. case 'playing':
  132. this.player.seek(newValue)
  133. break;
  134. case 'waiting':
  135. break;
  136. case 'error':
  137. break;
  138. case 'ended':
  139. break;
  140. default:
  141. break;
  142. }
  143. // this.player.seek(newValue)
  144. }
  145. },
  146. playAli() {
  147. //配置播放器
  148. var player = new Aliplayer({
  149. id: "wgy-player-test",
  150. "vid": 'b997f16cb9cb474cb93526cff77d8801',
  151. "playauth": this.playAuth,
  152. // "playConfig": {
  153. // "EncryptType": 'AliyunVoDEncryption'
  154. // },
  155. "qualitySort": "asc",
  156. "format": "m3u8",
  157. "mediaType": "video",
  158. "encryptType": 1,
  159. "progressMarkers": this.progressMarkers,
  160. "width": '100%',
  161. "height": '500px',
  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.one('canplay', function() {
  172. console.log('canplay', this.player.tag);
  173. player.tag.play();
  174. });
  175. },
  176. loadWebPlayerSDK() {
  177. return new Promise((resolve, reject) => {
  178. const s_tag = document.createElement('script'); // 引入播放器js
  179. s_tag.type = 'text/javascript';
  180. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  181. s_tag.charset = 'utf-8';
  182. s_tag.onload = () => {
  183. // this.checkValue();
  184. resolve();
  185. }
  186. document.body.appendChild(s_tag);
  187. const l_tag = document.createElement('link'); // 引入播放器css
  188. l_tag.rel = 'stylesheet';
  189. l_tag.href =
  190. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  191. document.body.appendChild(l_tag);
  192. });
  193. },
  194. }
  195. }
  196. </script>