questionJiexi.vue 5.0 KB

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