questionJiexi.vue 5.7 KB

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