questionJiexi.vue 5.7 KB

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