lookShipin.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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">视频播放</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. <text class="content-kcwz">课程位置:{{item.time}}</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. } from "@/utils/common.js"
  54. export default {
  55. data() {
  56. return {
  57. pageData: null, //上个页面获取的视频参数(视频id)
  58. playAuth: "", //播放凭证
  59. progressMarkers: [],
  60. jieName: '',
  61. hideFlag: 'show',
  62. videoId: "", //阿里云视频id
  63. seekTime: ''
  64. }
  65. },
  66. onLoad(options) {
  67. let data = JSON.parse(options.studyData)
  68. console.log(data);
  69. this.pageData = {
  70. ...data
  71. }
  72. console.log(this.pageData);
  73. this.videoId = data.videoId
  74. this.jieName = data.jieName
  75. this.progressMarkers = data.progressMarkers
  76. this.getLive(); //获取播放凭证
  77. },
  78. onHide() {
  79. console.log('onHideonHideonHideonHide');
  80. this.hideFlag = 'hide'
  81. },
  82. onUnload() {
  83. console.log('onUnloadonUnloadonUnloadonUnloadonUnload');
  84. this.hideFlag = 'hide'
  85. },
  86. methods: {
  87. playEnd(data) {
  88. this.$refs.popupRef.open();
  89. },
  90. goBack() {
  91. this.$refs.popupRef.close();
  92. this.goUpPage()
  93. },
  94. goNext() {
  95. this.$refs.popupRef.close();
  96. toast("暂无此功能");
  97. return false
  98. },
  99. getLive() {
  100. let req = {
  101. videoId: this.videoId
  102. }
  103. getVideoAuth(req).then(res => {
  104. this.playAuth = res.data
  105. })
  106. },
  107. markersClick(data) {
  108. console.log(data)
  109. this.seekTime = data.offset
  110. },
  111. goUpPage() {
  112. // this.$refs.popupRef.open();
  113. uni.navigateTo({
  114. // url: `/pages/study/index?xueqi=${data.activeXueqi}&nianji=${data.activeNianji}&flag=selectGrades`
  115. url: `/pages/study/index?xueqi=${this.pageData.xueqi}&nianji=${this.pageData.nianji}&zhangId=${this.pageData.zhangId}`
  116. })
  117. }
  118. },
  119. created() {
  120. // console.log("getLive")
  121. // this.getLive(); //获取播放凭证
  122. },
  123. }
  124. </script>
  125. <script module="renderScript" lang="renderjs">
  126. export default {
  127. mounted() {
  128. console.log("renderScript1")
  129. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  130. this.loadWebPlayerSDK()
  131. },
  132. data() {
  133. return {
  134. player: null,
  135. playAuth: '',
  136. videoId: '',
  137. progressMarkers: [],
  138. seekTime: ''
  139. }
  140. },
  141. methods: {
  142. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  143. // console.log('service层中的options发生变化')
  144. // console.log('新值', newValue)
  145. // console.log('旧值', oldValue)
  146. // ownerInstance和this.$ownerInstance一样,可用来向service层通信
  147. // instance和ownerInstance的区别是:
  148. // instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
  149. // instance的作用目前尚不明确,官方没有给出用法
  150. if (newValue) {
  151. this.playAuth = newValue
  152. this.playAli()
  153. }
  154. },
  155. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  156. if (newValue) {
  157. this.videoId = newValue
  158. }
  159. },
  160. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  161. if (this.player) {
  162. this.player.pause()
  163. }
  164. },
  165. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  166. if (newValue) {
  167. this.progressMarkers = newValue
  168. }
  169. },
  170. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  171. if (newValue) {
  172. console.log(newValue, 'newValuenewValuenewValuenewValuenewValue')
  173. console.log(this.player.getStatus(), 'newValuenewValuenewValuenewValuenewValue')
  174. this.player.play()
  175. this.player.seek(newValue)
  176. // switch (this.player.getStatus()) {
  177. // case 'init':
  178. // break;
  179. // case 'ready':
  180. // break;
  181. // case 'loading':
  182. // this.player.play()
  183. // this.player.seek(newValue)
  184. // break;
  185. // case 'play':
  186. // this.player.seek(newValue)
  187. // break;
  188. // case 'pause':
  189. // this.player.play()
  190. // this.player.seek(newValue)
  191. // break;
  192. // case 'playing':
  193. // this.player.seek(newValue)
  194. // break;
  195. // case 'waiting':
  196. // break;
  197. // case 'error':
  198. // break;
  199. // case 'ended':
  200. // break;
  201. // default:
  202. // break;
  203. // }
  204. // this.player.seek(newValue)
  205. }
  206. },
  207. playAli() {
  208. let that = this
  209. //配置播放器
  210. var player = new Aliplayer({
  211. id: "wgy-player-test",
  212. "vid": this.videoId,
  213. "playauth": this.playAuth,
  214. // "playConfig": {
  215. // "EncryptType": 'AliyunVoDEncryption'
  216. // },
  217. "skinLayout": [{
  218. "name": "bigPlayButton",
  219. "align": "blabs",
  220. "x": 30,
  221. "y": 80
  222. },
  223. {
  224. "name": "controlBar",
  225. "align": "blabs",
  226. "x": 0,
  227. "y": 0,
  228. "children": [{
  229. "name": "progress",
  230. "align": "blabs",
  231. "x": 0,
  232. "y": 44
  233. },
  234. {
  235. "name": "playButton",
  236. "align": "tl",
  237. "x": 15,
  238. "y": 12
  239. },
  240. {
  241. "name": "fullScreenButton",
  242. "align": "tr",
  243. "x": 10,
  244. "y": 12
  245. }
  246. ]
  247. }
  248. ],
  249. "qualitySort": "asc",
  250. "format": "mp4",
  251. "mediaType": "video",
  252. "encryptType": 1,
  253. "progressMarkers": this.progressMarkers,
  254. "width": '100%',
  255. "height": '500px',
  256. "autoplay": false,
  257. "isLive": false,
  258. "rePlay": false,
  259. "playsinline": true,
  260. "preload": false,
  261. "controlBarVisibility": "hover",
  262. "useH5Prism": true
  263. }, function(player) {});
  264. this.player = player;
  265. player.one('canplay', function() {
  266. console.log('canplay', this.player.tag);
  267. player.tag.play();
  268. });
  269. player.on('ended', function() {
  270. that.$ownerInstance.callMethod('playEnd', {
  271. data: 'end'
  272. })
  273. // uni.$emit('playEnd', {
  274. // data: 'end'
  275. // });
  276. });
  277. },
  278. loadWebPlayerSDK() {
  279. return new Promise((resolve, reject) => {
  280. const s_tag = document.createElement('script'); // 引入播放器js
  281. s_tag.type = 'text/javascript';
  282. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  283. s_tag.charset = 'utf-8';
  284. s_tag.onload = () => {
  285. // this.playAli()
  286. resolve();
  287. }
  288. document.body.appendChild(s_tag);
  289. const l_tag = document.createElement('link'); // 引入播放器css
  290. l_tag.rel = 'stylesheet';
  291. l_tag.href =
  292. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  293. document.body.appendChild(l_tag);
  294. });
  295. },
  296. }
  297. }
  298. </script>