questionJiexi.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. isFirst: -1,
  108. }
  109. },
  110. methods: {
  111. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  112. if (newValue) {
  113. this.playAuth = newValue
  114. this.loadWebPlayerSDK()
  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. if (this.isFirst == 0) {
  143. this.isFirst = -1
  144. return;
  145. }
  146. this.player = null;
  147. //配置播放器
  148. var player = new Aliplayer({
  149. id: "wgy-player-test",
  150. "vid": this.videoId,
  151. "playauth": this.playAuth,
  152. // "playConfig": {
  153. // "EncryptType": 'AliyunVoDEncryption'
  154. // },
  155. "skinLayout": [{
  156. "name": "bigPlayButton",
  157. "align": "blabs",
  158. "x": 30,
  159. "y": 80
  160. },
  161. {
  162. "name": "controlBar",
  163. "align": "blabs",
  164. "x": 0,
  165. "y": 0,
  166. "children": [{
  167. "name": "progress",
  168. "align": "blabs",
  169. "x": 0,
  170. "y": 44
  171. },
  172. {
  173. "name": "playButton",
  174. "align": "tl",
  175. "x": 15,
  176. "y": 12
  177. },
  178. {
  179. "name": "fullScreenButton",
  180. "align": "tr",
  181. "x": 10,
  182. "y": 12
  183. },
  184. {
  185. "name": "timeDisplay",
  186. "align": "tl",
  187. "x": 10,
  188. "y": 7
  189. }
  190. ]
  191. }
  192. ],
  193. "qualitySort": "asc",
  194. "format": "mp4",
  195. "mediaType": "video",
  196. "encryptType": 1,
  197. "progressMarkers": this.progressMarkers,
  198. "width": '100%',
  199. "height": '500px',
  200. "autoplay": false,
  201. "isLive": false,
  202. "rePlay": false,
  203. "playsinline": true,
  204. "preload": false,
  205. "controlBarVisibility": "hover",
  206. "useH5Prism": true
  207. }, function(player) {});
  208. this.player = player;
  209. player.one('canplay', function() {
  210. console.log('canplay', this.player.tag);
  211. player.tag.play();
  212. });
  213. this.isFirst ++;
  214. },
  215. loadWebPlayerSDK() {
  216. return new Promise((resolve, reject) => {
  217. const s_tag = document.createElement('script'); // 引入播放器js
  218. s_tag.type = 'text/javascript';
  219. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  220. s_tag.charset = 'utf-8';
  221. s_tag.onload = () => {
  222. this.playAli()
  223. resolve();
  224. }
  225. document.body.appendChild(s_tag);
  226. const l_tag = document.createElement('link'); // 引入播放器css
  227. l_tag.rel = 'stylesheet';
  228. l_tag.href =
  229. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  230. document.body.appendChild(l_tag);
  231. });
  232. },
  233. }
  234. }
  235. </script>