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. this.loadWebPlayerSDK()
  100. },
  101. data() {
  102. return {
  103. player: null,
  104. playAuth: '',
  105. videoId: '',
  106. progressMarkers: [],
  107. seekTime: ''
  108. }
  109. },
  110. methods: {
  111. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  112. if (newValue) {
  113. this.playAuth = newValue
  114. this.playAli()
  115. }
  116. },
  117. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  118. if (newValue) {
  119. this.videoId = newValue
  120. }
  121. },
  122. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  123. if (this.player) {
  124. this.player.pause()
  125. }
  126. },
  127. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  128. if (newValue) {
  129. this.progressMarkers = newValue
  130. }
  131. },
  132. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  133. if (newValue) {
  134. console.log(newValue, 'newValuenewValuenewValuenewValuenewValue')
  135. console.log(this.player.getStatus(), 'newValuenewValuenewValuenewValuenewValue')
  136. this.player.play()
  137. this.player.seek(newValue)
  138. // this.player.seek(newValue)
  139. }
  140. },
  141. playAli() {
  142. //配置播放器
  143. var player = new Aliplayer({
  144. id: "wgy-player-test",
  145. "vid": this.videoId,
  146. "playauth": this.playAuth,
  147. // "playConfig": {
  148. // "EncryptType": 'AliyunVoDEncryption'
  149. // },
  150. "skinLayout": [{
  151. "name": "bigPlayButton",
  152. "align": "blabs",
  153. "x": 30,
  154. "y": 80
  155. },
  156. {
  157. "name": "controlBar",
  158. "align": "blabs",
  159. "x": 0,
  160. "y": 0,
  161. "children": [{
  162. "name": "progress",
  163. "align": "blabs",
  164. "x": 0,
  165. "y": 44
  166. },
  167. {
  168. "name": "playButton",
  169. "align": "tl",
  170. "x": 15,
  171. "y": 12
  172. },
  173. {
  174. "name": "fullScreenButton",
  175. "align": "tr",
  176. "x": 10,
  177. "y": 12
  178. }
  179. ]
  180. }
  181. ],
  182. "qualitySort": "asc",
  183. "format": "mp4",
  184. "mediaType": "video",
  185. "encryptType": 1,
  186. "progressMarkers": this.progressMarkers,
  187. "width": '100%',
  188. "height": '500px',
  189. "autoplay": false,
  190. "isLive": false,
  191. "rePlay": false,
  192. "playsinline": true,
  193. "preload": false,
  194. "controlBarVisibility": "hover",
  195. "useH5Prism": true
  196. }, function(player) {});
  197. this.player = player;
  198. player.one('canplay', function() {
  199. console.log('canplay', this.player.tag);
  200. player.tag.play();
  201. });
  202. },
  203. loadWebPlayerSDK() {
  204. return new Promise((resolve, reject) => {
  205. const s_tag = document.createElement('script'); // 引入播放器js
  206. s_tag.type = 'text/javascript';
  207. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  208. s_tag.charset = 'utf-8';
  209. s_tag.onload = () => {
  210. // this.checkValue();
  211. resolve();
  212. }
  213. document.body.appendChild(s_tag);
  214. const l_tag = document.createElement('link'); // 引入播放器css
  215. l_tag.rel = 'stylesheet';
  216. l_tag.href =
  217. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  218. document.body.appendChild(l_tag);
  219. });
  220. },
  221. }
  222. }
  223. </script>