questionJiexi.vue 7.8 KB

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