questionJiexi.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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="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. this.hideFlag = 'hide'
  71. },
  72. onUnload() {
  73. this.hideFlag = 'hide'
  74. },
  75. methods: {
  76. playEnd(data) {
  77. plus.screen.lockOrientation('portrait-primary');
  78. this.$refs.popupRef2.open();
  79. },
  80. goBack() {
  81. plus.screen.unlockOrientation();
  82. this.$refs.popupRef2.close();
  83. this.$refs.popupRef.close()
  84. },
  85. goNext() {
  86. plus.screen.unlockOrientation();
  87. this.$refs.popupRef2.close();
  88. },
  89. showPopup(item) {
  90. this.data = item;
  91. this.videoId = item.jiangjie
  92. //this.videoId = 'b997f16cb9cb474cb93526cff77d8801'
  93. // this.progressMarkers = item.progressMarkers
  94. this.getLive(); //获取播放凭证
  95. this.$refs.popupRef.open()
  96. },
  97. handleBack(item) {
  98. this.$refs.popupRef.close()
  99. },
  100. getLive() {
  101. let req = {
  102. videoId: this.videoId
  103. }
  104. getVideoAuth(req).then(res => {
  105. this.playAuth = res.data
  106. })
  107. },
  108. markersClick(data) {
  109. this.seekTime = ""
  110. this.$nextTick(() => {
  111. this.seekTime = data.offset
  112. });
  113. },
  114. },
  115. created() {
  116. // console.log("getLive")
  117. // this.getLive(); //获取播放凭证
  118. },
  119. }
  120. </script>
  121. <script module="renderScript" lang="renderjs">
  122. export default {
  123. mounted() {
  124. console.log("renderScript1")
  125. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  126. },
  127. data() {
  128. return {
  129. player: null,
  130. playAuth: '',
  131. videoId: '',
  132. progressMarkers: [],
  133. isFullScreen: false,
  134. seekTime: '',
  135. isFirst: -1,
  136. }
  137. },
  138. methods: {
  139. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  140. if (newValue) {
  141. this.playAuth = newValue
  142. this.loadWebPlayerSDK()
  143. }
  144. },
  145. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  146. if (newValue) {
  147. this.videoId = newValue
  148. }
  149. },
  150. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  151. if (this.player) {
  152. this.player.pause()
  153. }
  154. },
  155. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  156. if (newValue) {
  157. this.progressMarkers = newValue
  158. }
  159. },
  160. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  161. if (newValue) {
  162. console.log(newValue, 'newValuenewValuenewValuenewValuenewValue')
  163. console.log(this.player.getStatus(), 'newValuenewValuenewValuenewValuenewValue')
  164. this.player.play()
  165. this.player.seek(newValue)
  166. // this.player.seek(newValue)
  167. }
  168. },
  169. playAli() {
  170. if (this.isFirst == 0) {
  171. this.isFirst = -1
  172. return;
  173. }
  174. this.player = null;
  175. let that = this
  176. //配置播放器
  177. var player = new Aliplayer({
  178. id: "wgy-player-test",
  179. "vid": this.videoId,
  180. "playauth": this.playAuth,
  181. extraInfo: {
  182. poster: 'noposter'
  183. },
  184. fullscreenEvents: {
  185. fullscreenChange: (isFull) => {
  186. this.isFullScreen = isFull
  187. }
  188. },
  189. // "playConfig": {
  190. // "EncryptType": 'AliyunVoDEncryption'
  191. // },
  192. "skinLayout": [{
  193. "name": "bigPlayButton",
  194. "align": "blabs",
  195. "x": 30,
  196. "y": 80
  197. },
  198. {
  199. "name": "controlBar",
  200. "align": "blabs",
  201. "x": 0,
  202. "y": 0,
  203. "children": [{
  204. "name": "progress",
  205. "align": "blabs",
  206. "x": 0,
  207. "y": 44
  208. },
  209. {
  210. "name": "playButton",
  211. "align": "tl",
  212. "x": 15,
  213. "y": 12
  214. },
  215. {
  216. "name": "fullScreenButton",
  217. "align": "tr",
  218. "x": 10,
  219. "y": 12
  220. },
  221. {
  222. "name": "timeDisplay",
  223. "align": "tr",
  224. "x": 10,
  225. "y": 5
  226. }
  227. ]
  228. }
  229. ],
  230. "qualitySort": "asc",
  231. "format": "mp4",
  232. "mediaType": "video",
  233. "encryptType": 1,
  234. "progressMarkers": this.progressMarkers,
  235. "width": '100%',
  236. "height": '500px',
  237. "autoplay": false,
  238. "isLive": false,
  239. "rePlay": false,
  240. "playsinline": true,
  241. "preload": false,
  242. "controlBarVisibility": "hover",
  243. "useH5Prism": true
  244. }, function(player) {});
  245. this.player = player;
  246. player.one('canplay', function() {
  247. console.log('canplay', this.player.tag);
  248. player.tag.play();
  249. });
  250. player.on('ended', function(data) {
  251. that.exitFullScreen();
  252. that.$ownerInstance.callMethod('playEnd', {
  253. data: 'end'
  254. })
  255. });
  256. this.isFirst++;
  257. },
  258. exitFullScreen() {
  259. if (document.exitFullscreen) {
  260. document.exitFullscreen(); // 标准方法
  261. } else if (document.mozCancelFullScreen) { // Firefox
  262. document.mozCancelFullScreen();
  263. } else if (document.webkitExitFullscreen) { // Chrome, Safari & Opera
  264. document.webkitExitFullscreen();
  265. } else if (document.msExitFullscreen) { // IE/Edge
  266. document.msExitFullscreen();
  267. }
  268. },
  269. loadWebPlayerSDK() {
  270. return new Promise((resolve, reject) => {
  271. const s_tag = document.createElement('script'); // 引入播放器js
  272. s_tag.type = 'text/javascript';
  273. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  274. s_tag.charset = 'utf-8';
  275. s_tag.onload = () => {
  276. this.playAli()
  277. resolve();
  278. }
  279. document.body.appendChild(s_tag);
  280. const l_tag = document.createElement('link'); // 引入播放器css
  281. l_tag.rel = 'stylesheet';
  282. l_tag.href =
  283. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  284. document.body.appendChild(l_tag);
  285. });
  286. },
  287. }
  288. }
  289. </script>