questionJiexi.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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"
  21. :playAuth="playAuth"
  22. :change:playAuth="renderScript.receiveMsg"
  23. :videoId="videoId"
  24. :change:videoId="renderScript.videoId"
  25. :seekTime="seekTime"
  26. :change:seekTime="renderScript.seekTimeFun">
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </uni-popup>
  33. </view>
  34. </template>
  35. <script>
  36. import {
  37. onLoad,
  38. onReady
  39. } from '@dcloudio/uni-app';
  40. import {
  41. videoPolicy,
  42. getVideoAuth,
  43. getVideoRefresh
  44. } from "@/api/shipin.js"
  45. export default {
  46. data() {
  47. return {
  48. pageData: null, //上个页面获取的视频参数(视频id)
  49. playAuth: "", //播放凭证
  50. progressMarkers: [],
  51. videoId: "", //阿里云视频id
  52. seekTime: '',
  53. data:{}
  54. }
  55. },
  56. methods: {
  57. showPopup(item){
  58. this.data = item;
  59. this.videoId = item.jiangjie
  60. //this.videoId = 'b997f16cb9cb474cb93526cff77d8801'
  61. // this.progressMarkers = item.progressMarkers
  62. this.getLive(); //获取播放凭证
  63. this.$refs.popupRef.open()
  64. },
  65. handleBack(item){
  66. this.$refs.popupRef.close()
  67. },
  68. getLive() {
  69. let req = {
  70. videoId: this.videoId
  71. }
  72. getVideoAuth(req).then(res => {
  73. this.playAuth = res.data
  74. })
  75. },
  76. markersClick(data) {
  77. console.log(data)
  78. this.seekTime = data.offset
  79. },
  80. },
  81. created() {
  82. // console.log("getLive")
  83. // this.getLive(); //获取播放凭证
  84. },
  85. }
  86. </script>
  87. <script module="renderScript" lang="renderjs">
  88. export default {
  89. mounted() {
  90. console.log("renderScript1")
  91. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  92. this.loadWebPlayerSDK()
  93. },
  94. data() {
  95. return {
  96. player: null,
  97. playAuth: '',
  98. videoId: '',
  99. progressMarkers: [],
  100. seekTime: ''
  101. }
  102. },
  103. methods: {
  104. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  105. if (newValue) {
  106. this.playAuth = newValue
  107. this.playAli()
  108. }
  109. },
  110. videoId(newValue, oldValue, ownerInstance, instance) {
  111. if (newValue) {
  112. this.videoId = newValue
  113. }
  114. },
  115. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  116. if (newValue) {
  117. this.progressMarkers = newValue
  118. }
  119. },
  120. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  121. if (newValue) {
  122. console.log(newValue, 'newValuenewValuenewValuenewValuenewValue')
  123. console.log(this.player.getStatus(), 'newValuenewValuenewValuenewValuenewValue')
  124. this.player.play()
  125. this.player.seek(newValue)
  126. // this.player.seek(newValue)
  127. }
  128. },
  129. playAli() {
  130. //配置播放器
  131. var player = new Aliplayer({
  132. id: "wgy-player-test",
  133. "vid": this.videoId,
  134. "playauth": this.playAuth,
  135. // "playConfig": {
  136. // "EncryptType": 'AliyunVoDEncryption'
  137. // },
  138. "qualitySort": "asc",
  139. "format": "mp4",
  140. "mediaType": "video",
  141. "encryptType": 1,
  142. "progressMarkers": this.progressMarkers,
  143. "width": '100%',
  144. "height": '500px',
  145. "autoplay": false,
  146. "isLive": false,
  147. "rePlay": false,
  148. "playsinline": true,
  149. "preload": false,
  150. "controlBarVisibility": "hover",
  151. "useH5Prism": true
  152. }, function(player) {});
  153. this.player = player;
  154. player.one('canplay', function() {
  155. console.log('canplay', this.player.tag);
  156. player.tag.play();
  157. });
  158. },
  159. loadWebPlayerSDK() {
  160. return new Promise((resolve, reject) => {
  161. const s_tag = document.createElement('script'); // 引入播放器js
  162. s_tag.type = 'text/javascript';
  163. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  164. s_tag.charset = 'utf-8';
  165. s_tag.onload = () => {
  166. // this.checkValue();
  167. resolve();
  168. }
  169. document.body.appendChild(s_tag);
  170. const l_tag = document.createElement('link'); // 引入播放器css
  171. l_tag.rel = 'stylesheet';
  172. l_tag.href =
  173. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  174. document.body.appendChild(l_tag);
  175. });
  176. },
  177. }
  178. }
  179. </script>