lookShipin.vue 10.0 KB

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