questionJiexi.vue 6.4 KB

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