questionJiexi.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <view>
  3. <uni-popup ref="popupRef" :animation="false" :is-mask-click="false" type="top"
  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="ezy-dajx-page">
  7. <view class="icon-title-navBar-box">
  8. <view @click="handleBack" class="nav-bar-icon"></view>
  9. <view class="nav-bar-title">单元测试</view>
  10. </view>
  11. <view class="shiti-frame-box">
  12. <view class="dajx-content-box">
  13. <!-- 思路分析 -->
  14. <view class="slfx-title"></view>
  15. <!-- <view class="slfx-content"> {{data.answer}}</view> -->
  16. <rich-text class="slfx-content" :nodes="data.answer"></rich-text>
  17. <!-- 视频讲解 -->
  18. <view class="spjj-title"></view>
  19. <view class="ezy-video-box">
  20. <!-- 这里放视频 ↓ -->
  21. <view class="ezy-video" ref="videoContent" id="wgy-player-test" :playAuth="playAuth"
  22. :change:playAuth="renderScript.receiveMsg" :videoId="videoId"
  23. :change:videoId="renderScript.videoIdFun" :hideFlag="hideFlag"
  24. :change:hideFlag="renderScript.hideFlagFun" :seekTime="seekTime"
  25. :change:seekTime="renderScript.seekTimeFun">
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </uni-popup>
  32. <uni-popup ref="popupRef2" :animation="false" :is-mask-click="false" type="top"
  33. mask-background-color="rgba(51, 137, 217, 0.65);">
  34. <view class="course-finish-dialog">
  35. <view class="text-score">{{credit}}</view>
  36. <view class="course-btn-box">
  37. <view @click="goBack" class="return-btn"></view>
  38. <view @click="goNext" class="continue-btn"></view>
  39. </view>
  40. </view>
  41. </uni-popup>
  42. </view>
  43. </template>
  44. <script>
  45. import {
  46. onLoad,
  47. onReady
  48. } from '@dcloudio/uni-app';
  49. import {
  50. getVideoAuth,
  51. } from "@/api/shipin.js"
  52. export default {
  53. props: {
  54. cardId: {
  55. type: [String, Number],
  56. default: 1
  57. }
  58. },
  59. data() {
  60. return {
  61. pageData: null, //上个页面获取的视频参数(视频id)
  62. playAuth: "", //播放凭证
  63. progressMarkers: [],
  64. videoId: "", //阿里云视频id
  65. seekTime: '',
  66. hideFlag: 'show',
  67. data: {},
  68. }
  69. },
  70. onHide() {
  71. console.log('onHideonHideonHideonHide');
  72. this.hideFlag = 'hide'
  73. },
  74. onUnload() {
  75. console.log('onUnloadonUnloadonUnloadonUnloadonUnload');
  76. this.hideFlag = 'hide'
  77. },
  78. methods: {
  79. playEnd(data) {
  80. console.log('data', data);
  81. console.log('111111');
  82. plus.screen.lockOrientation('portrait-primary');
  83. this.$refs.popupRef2.open();
  84. },
  85. goBack() {
  86. plus.screen.unlockOrientation();
  87. this.$refs.popupRef2.close();
  88. this.$refs.popupRef.close()
  89. },
  90. goNext() {
  91. plus.screen.unlockOrientation();
  92. this.$refs.popupRef2.close();
  93. },
  94. showPopup(item) {
  95. this.data = item;
  96. this.videoId = item.jiangjie
  97. //this.videoId = 'b997f16cb9cb474cb93526cff77d8801'
  98. // this.progressMarkers = item.progressMarkers
  99. this.getLive(); //获取播放凭证
  100. this.$refs.popupRef.open()
  101. },
  102. handleBack(item) {
  103. this.$refs.popupRef.close()
  104. },
  105. getLive() {
  106. let req = {
  107. videoId: this.videoId
  108. }
  109. getVideoAuth(req).then(res => {
  110. this.playAuth = res.data
  111. })
  112. },
  113. markersClick(data) {
  114. this.seekTime = ""
  115. this.$nextTick(() => {
  116. this.seekTime = data.offset
  117. });
  118. },
  119. /*courseBjFun() {
  120. const cardId = Number(this.cardId);
  121. switch (cardId) {
  122. case 1:
  123. return 'static/images/course/couse-shuxue-bj.png'
  124. break;
  125. case 2:
  126. return 'static/images/course/course-yingyu-bj.png'
  127. break;
  128. default:
  129. break;
  130. }
  131. }*/
  132. },
  133. created() {
  134. // console.log("getLive")
  135. // this.getLive(); //获取播放凭证
  136. },
  137. }
  138. </script>
  139. <script module="renderScript" lang="renderjs">
  140. export default {
  141. mounted() {
  142. console.log("renderScript1")
  143. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  144. },
  145. data() {
  146. return {
  147. player: null,
  148. playAuth: '',
  149. videoId: '',
  150. progressMarkers: [],
  151. isFullScreen: false,
  152. seekTime: '',
  153. isFirst: -1,
  154. }
  155. },
  156. methods: {
  157. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  158. if (newValue) {
  159. this.playAuth = newValue
  160. this.loadWebPlayerSDK()
  161. }
  162. },
  163. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  164. if (newValue) {
  165. this.videoId = newValue
  166. }
  167. },
  168. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  169. if (this.player) {
  170. this.player.pause()
  171. }
  172. },
  173. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  174. if (newValue) {
  175. this.progressMarkers = newValue
  176. }
  177. },
  178. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  179. if (newValue) {
  180. console.log(newValue, 'newValuenewValuenewValuenewValuenewValue')
  181. console.log(this.player.getStatus(), 'newValuenewValuenewValuenewValuenewValue')
  182. this.player.play()
  183. this.player.seek(newValue)
  184. // this.player.seek(newValue)
  185. }
  186. },
  187. playAli() {
  188. if (this.isFirst == 0) {
  189. this.isFirst = -1
  190. return;
  191. }
  192. this.player = null;
  193. let that = this
  194. //配置播放器
  195. var player = new Aliplayer({
  196. id: "wgy-player-test",
  197. "vid": this.videoId,
  198. "playauth": this.playAuth,
  199. extraInfo: {
  200. poster: 'noposter'
  201. },
  202. fullscreenEvents: {
  203. fullscreenChange: (isFull) => {
  204. this.isFullScreen = isFull
  205. }
  206. },
  207. // "playConfig": {
  208. // "EncryptType": 'AliyunVoDEncryption'
  209. // },
  210. "skinLayout": [{
  211. "name": "bigPlayButton",
  212. "align": "blabs",
  213. "x": 30,
  214. "y": 80
  215. },
  216. {
  217. "name": "controlBar",
  218. "align": "blabs",
  219. "x": 0,
  220. "y": 0,
  221. "children": [{
  222. "name": "progress",
  223. "align": "blabs",
  224. "x": 0,
  225. "y": 44
  226. },
  227. {
  228. "name": "playButton",
  229. "align": "tl",
  230. "x": 15,
  231. "y": 12
  232. },
  233. {
  234. "name": "fullScreenButton",
  235. "align": "tr",
  236. "x": 10,
  237. "y": 12
  238. },
  239. {
  240. "name": "timeDisplay",
  241. "align": "tr",
  242. "x": 10,
  243. "y": 5
  244. }
  245. ]
  246. }
  247. ],
  248. "qualitySort": "asc",
  249. "format": "mp4",
  250. "mediaType": "video",
  251. "encryptType": 1,
  252. "progressMarkers": this.progressMarkers,
  253. "width": '100%',
  254. "height": '500px',
  255. "autoplay": false,
  256. "isLive": false,
  257. "rePlay": false,
  258. "playsinline": true,
  259. "preload": false,
  260. "controlBarVisibility": "hover",
  261. "useH5Prism": true
  262. }, function(player) {});
  263. this.player = player;
  264. player.one('canplay', function() {
  265. console.log('canplay', this.player.tag);
  266. player.tag.play();
  267. });
  268. player.on('ended', function(data) {
  269. that.exitFullScreen();
  270. that.$ownerInstance.callMethod('playEnd', {
  271. data: 'end'
  272. })
  273. });
  274. this.isFirst++;
  275. },
  276. exitFullScreen() {
  277. if (document.exitFullscreen) {
  278. document.exitFullscreen(); // 标准方法
  279. } else if (document.mozCancelFullScreen) { // Firefox
  280. document.mozCancelFullScreen();
  281. } else if (document.webkitExitFullscreen) { // Chrome, Safari & Opera
  282. document.webkitExitFullscreen();
  283. } else if (document.msExitFullscreen) { // IE/Edge
  284. document.msExitFullscreen();
  285. }
  286. },
  287. loadWebPlayerSDK() {
  288. return new Promise((resolve, reject) => {
  289. const s_tag = document.createElement('script'); // 引入播放器js
  290. s_tag.type = 'text/javascript';
  291. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  292. s_tag.charset = 'utf-8';
  293. s_tag.onload = () => {
  294. this.playAli()
  295. resolve();
  296. }
  297. document.body.appendChild(s_tag);
  298. const l_tag = document.createElement('link'); // 引入播放器css
  299. l_tag.rel = 'stylesheet';
  300. l_tag.href =
  301. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  302. document.body.appendChild(l_tag);
  303. });
  304. },
  305. }
  306. }
  307. </script>