questionJiexi.vue 7.3 KB

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