lookShipin.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <template>
  2. <view class="ezy-course-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="goUpPage" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">{{shipinTitle}}</text>
  6. </view>
  7. <view ref="videoContent" id="wgy-player-test" :playAuth="playAuth" :change:playAuth="renderScript.receiveMsg"
  8. :videoId="videoId" :change:videoId="renderScript.videoIdFun" :hideFlag="hideFlag"
  9. :change:hideFlag="renderScript.hideFlagFun" :progressMarkers="progressMarkers"
  10. :change:progressMarkers="renderScript.progressMarkersMsg" :seekTime="seekTime"
  11. :change:seekTime="renderScript.seekTimeFun" class="course-video-box">
  12. </view>
  13. <view class="course-content-border">
  14. <view class="course-content-box">
  15. <!-- <view class="course-title">{{jieName}}</view> -->
  16. <view v-for="(item,index) in progressMarkers" :key="index" @click="markersClick(item)">
  17. <view class="title-play-box">
  18. <text class="course-title">{{item.title}}</text>
  19. <view class="course-play-btn" @click="markersClick(item)"></view>
  20. </view>
  21. <rich-text :nodes="item.describe" class="course-content-item"></rich-text>
  22. </view>
  23. </view>
  24. </view>
  25. <uni-popup ref="popupRef" :animation="false" :is-mask-click="false"
  26. mask-background-color="rgba(255, 255, 255, 0.6);">
  27. <view class="course-score-dialog">
  28. <view class="text-score">20</view>
  29. <view class="course-btn-box">
  30. <view @click="goBack" class="return-btn"></view>
  31. <view @click="goNext" class="continue-btn"></view>
  32. </view>
  33. </view>
  34. </uni-popup>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. ref
  40. } from 'vue';
  41. import {
  42. onLoad,
  43. onReady
  44. } from '@dcloudio/uni-app';
  45. import {
  46. videoPolicy,
  47. getVideoAuth,
  48. getVideoRefresh
  49. } from "@/api/shipin.js"
  50. import {
  51. toast,
  52. getUserIdentity
  53. } from "@/utils/common";
  54. import {
  55. userZhangNextInfo,
  56. } from "@/api/learnPlan.js"
  57. import cacheManager from "@/utils/cacheManager.js";
  58. export default {
  59. data() {
  60. return {
  61. pageData: null, //上个页面获取的视频参数(视频id)
  62. playAuth: "", //播放凭证
  63. progressMarkers: [],
  64. jieName: '',
  65. hideFlag: 'show',
  66. videoId: "", //阿里云视频id
  67. cardId: '',
  68. nianji: '',
  69. zhangId: '',
  70. seekTime: '',
  71. jieNumber: '',
  72. shipinTitle: '',
  73. cacheZhangInfo: {}
  74. }
  75. },
  76. onLoad(options) {
  77. if (!cacheManager.get('auth')) {
  78. // 游客
  79. this.videoId = options.videoId
  80. this.nianji = options.nianji
  81. this.zhangId = options.zhangId
  82. this.cardId = options.cardId
  83. this.getLive(); //获取播放凭证
  84. } else {
  85. this.init(options)
  86. }
  87. },
  88. onHide() {
  89. console.log('onHideonHideonHideonHide');
  90. this.hideFlag = 'hide'
  91. },
  92. onUnload() {
  93. console.log('onUnloadonUnloadonUnloadonUnloadonUnload');
  94. this.hideFlag = 'hide'
  95. },
  96. methods: {
  97. init(options) {
  98. this.jieNumber = options.jieNumber
  99. if (!(cacheManager.get('zhangInfo') && options.jieNumber)) {
  100. toast('数据错误,缓存丢失/ number丢失')
  101. return false
  102. }
  103. this.cacheZhangInfo = cacheManager.get('zhangInfo')
  104. let currentObject = this.cacheZhangInfo.jieList.find(item => item.number == options.jieNumber);
  105. this.shipinTitle = this.cacheZhangInfo.numberStr + ' ' + this.cacheZhangInfo.zhangName
  106. // lastFlag是否是本章最后一节,0否1是 type,1视频,2试题
  107. if (currentObject.lastFlag == 1 && currentObject.type == 2) {
  108. uni.redirectTo({
  109. url: `/pages/unitTest/index?jieNumber=` + currentObject.number
  110. })
  111. } else if (currentObject.lastFlag == 1 && currentObject.type == 1) {
  112. // 当前是本章最后一节,并且是 视频 切换下一章
  113. this.goNextZhang()
  114. } else {
  115. this.pageData = {
  116. ...currentObject
  117. }
  118. console.log(this.pageData);
  119. this.videoId = this.pageData.videoId
  120. this.jieName = this.pageData.jieName
  121. this.progressMarkers = this.pageData.jiedianList
  122. this.getLive(); //获取播放凭证
  123. }
  124. },
  125. goNextZhang() {
  126. let that = this
  127. let req = {
  128. nianji: that.currentObject.nianji,
  129. zhangId: that.currentObject.zhangId,
  130. cardId: that.currentObject.cardId,
  131. }
  132. userZhangNextInfo(req).then(res => {
  133. cacheManager.set('zhangInfo', res.data)
  134. cacheManager.updateObject('auth', {
  135. zhangId: res.data.zhangId,
  136. cardId: res.data.cardId,
  137. nianji: res.data.nianji,
  138. })
  139. that.init({
  140. jieNumber: 1
  141. })
  142. })
  143. },
  144. playEnd(data) {
  145. this.$refs.popupRef.open();
  146. },
  147. goBack() {
  148. this.$refs.popupRef.close();
  149. this.goUpPage()
  150. },
  151. goNext() {
  152. this.$refs.popupRef.close();
  153. this.hideFlag = "show"
  154. this.videoId = ''
  155. this.progressMarkers = []
  156. this.pageData = null
  157. this.playAuth = ''
  158. this.cacheZhangInfo = {}
  159. Number(this.jieNumber++)
  160. // this.init({
  161. // jieNumber: this.jieNumber
  162. // })
  163. uni.redirectTo({
  164. //url: '/pages/study/lookShipin?studyData=' + JSON.stringify(pageData)
  165. url: '/pages/study/lookShipin?jieNumber=' + this.jieNumber
  166. })
  167. },
  168. getLive() {
  169. let req = {
  170. videoId: this.videoId
  171. }
  172. getVideoAuth(req).then(res => {
  173. this.playAuth = res.data
  174. })
  175. },
  176. markersClick(data) {
  177. this.seekTime = ""
  178. this.$nextTick(() => {
  179. this.seekTime = data.offset
  180. });
  181. },
  182. goUpPage() {
  183. if (!cacheManager.get('auth')) {
  184. uni.redirectTo({
  185. url: '/pages/study/index?cardId=' + this.cardId+ '&nianji=' + this.nianji+ '&zhangId=' + this.zhangId
  186. })
  187. } else {
  188. uni.redirectTo({
  189. url: `/pages/study/index`
  190. })
  191. }
  192. }
  193. },
  194. created() {
  195. // console.log("getLive")
  196. // this.getLive(); //获取播放凭证
  197. },
  198. }
  199. </script>
  200. <script module="renderScript" lang="renderjs">
  201. export default {
  202. mounted() {
  203. console.log("renderScript1")
  204. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  205. this.loadWebPlayerSDK()
  206. },
  207. data() {
  208. return {
  209. player: null,
  210. playAuth: '',
  211. videoId: '',
  212. progressMarkers: [],
  213. seekTime: ''
  214. }
  215. },
  216. methods: {
  217. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  218. // console.log('service层中的options发生变化')
  219. // console.log('新值', newValue)
  220. // console.log('旧值', oldValue)
  221. // ownerInstance和this.$ownerInstance一样,可用来向service层通信
  222. // instance和ownerInstance的区别是:
  223. // instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
  224. // instance的作用目前尚不明确,官方没有给出用法
  225. if (newValue) {
  226. this.playAuth = ''
  227. this.playAuth = newValue
  228. this.playAli()
  229. }
  230. },
  231. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  232. if (newValue) {
  233. this.videoId = ''
  234. this.videoId = newValue
  235. }
  236. },
  237. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  238. if (this.player) {
  239. this.player.pause()
  240. }
  241. },
  242. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  243. if (newValue) {
  244. this.progressMarkers = newValue
  245. }
  246. },
  247. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  248. if (newValue) {
  249. this.player.play()
  250. this.player.seek(newValue)
  251. // switch (this.player.getStatus()) {
  252. // case 'init':
  253. // break;
  254. // case 'ready':
  255. // break;
  256. // case 'loading':
  257. // this.player.play()
  258. // this.player.seek(newValue)
  259. // break;
  260. // case 'play':
  261. // this.player.seek(newValue)
  262. // break;
  263. // case 'pause':
  264. // this.player.play()
  265. // this.player.seek(newValue)
  266. // break;
  267. // case 'playing':
  268. // this.player.seek(newValue)
  269. // break;
  270. // case 'waiting':
  271. // break;
  272. // case 'error':
  273. // break;
  274. // case 'ended':
  275. // break;
  276. // default:
  277. // break;
  278. // }
  279. // this.player.seek(newValue)
  280. }
  281. },
  282. playAli() {
  283. let that = this
  284. // console.log(this.videoId);
  285. // console.log(this.playAuth);
  286. //配置播放器
  287. var player = new Aliplayer({
  288. id: "wgy-player-test",
  289. "vid": this.videoId,
  290. "playauth": this.playAuth,
  291. // "playConfig": {
  292. // "EncryptType": 'AliyunVoDEncryption'
  293. // },
  294. "skinLayout": [{
  295. "name": "bigPlayButton",
  296. "align": "blabs",
  297. "x": 30,
  298. "y": 80
  299. },
  300. {
  301. "name": "controlBar",
  302. "align": "blabs",
  303. "x": 0,
  304. "y": 0,
  305. "children": [{
  306. "name": "progress",
  307. "align": "blabs",
  308. "x": 0,
  309. "y": 44
  310. },
  311. {
  312. "name": "playButton",
  313. "align": "tl",
  314. "x": 15,
  315. "y": 12
  316. },
  317. {
  318. "name": "fullScreenButton",
  319. "align": "tr",
  320. "x": 10,
  321. "y": 12
  322. }
  323. ]
  324. }
  325. ],
  326. "qualitySort": "asc",
  327. "format": "mp4",
  328. "mediaType": "video",
  329. "encryptType": 1,
  330. "progressMarkers": this.progressMarkers,
  331. "width": '100%',
  332. "height": '500px',
  333. "autoplay": false,
  334. "isLive": false,
  335. "rePlay": false,
  336. "playsinline": true,
  337. "preload": false,
  338. "controlBarVisibility": "hover",
  339. "useH5Prism": true
  340. }, function(player) {});
  341. this.player = player;
  342. player.on('canplay', function() {
  343. console.log('canplay', this.player.tag);
  344. player.tag.play();
  345. });
  346. player.on('ended', function() {
  347. that.$ownerInstance.callMethod('playEnd', {
  348. data: 'end'
  349. })
  350. // uni.$emit('playEnd', {
  351. // data: 'end'
  352. // });
  353. });
  354. },
  355. loadWebPlayerSDK() {
  356. return new Promise((resolve, reject) => {
  357. const s_tag = document.createElement('script'); // 引入播放器js
  358. s_tag.type = 'text/javascript';
  359. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  360. s_tag.charset = 'utf-8';
  361. s_tag.onload = () => {
  362. // this.playAli()
  363. resolve();
  364. }
  365. document.body.appendChild(s_tag);
  366. const l_tag = document.createElement('link'); // 引入播放器css
  367. l_tag.rel = 'stylesheet';
  368. l_tag.href =
  369. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  370. document.body.appendChild(l_tag);
  371. });
  372. },
  373. }
  374. }
  375. </script>