lookShipin.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. :progressMarkers="progressMarkers" :change:progressMarkers="renderScript.progressMarkersMsg"
  9. :seekTime="seekTime" :change:seekTime="renderScript.seekTimeFun" class="course-video-box">
  10. </view>
  11. <view class="course-content-border">
  12. <view class="course-content-box">
  13. <view class="course-title">{{jieName}}</view>
  14. <view v-for="(item,index) in progressMarkers" :key="index" @click="markersClick(item)"
  15. class="course-content-item">
  16. <view class="course-play-btn"></view>
  17. <view class="course-content">
  18. <text>{{item.title}}</text>
  19. <text class="content-kcwz">课程位置:{{item.time}}</text>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <uni-popup ref="popupRef" :animation="false" :is-mask-click="false"
  25. mask-background-color="rgba(255, 255, 255, 0.6);">
  26. <view class="course-score-dialog">
  27. <view class="text-score">20</view>
  28. <view class="course-btn-box">
  29. <view @click="goBack" class="return-btn"></view>
  30. <view @click="goNext" class="continue-btn"></view>
  31. </view>
  32. </view>
  33. </uni-popup>
  34. </view>
  35. </template>
  36. <script>
  37. import {
  38. ref
  39. } from 'vue';
  40. import {
  41. onLoad,
  42. onReady
  43. } from '@dcloudio/uni-app';
  44. import {
  45. videoPolicy,
  46. getVideoAuth,
  47. getVideoRefresh
  48. } from "@/api/shipin.js"
  49. import {
  50. toast
  51. } from "@/utils/common.js"
  52. export default {
  53. data() {
  54. return {
  55. pageData: null, //上个页面获取的视频参数(视频id)
  56. playAuth: "", //播放凭证
  57. progressMarkers: [],
  58. jieName: '',
  59. videoId: "", //阿里云视频id
  60. seekTime: ''
  61. }
  62. },
  63. onLoad(options) {
  64. let data = JSON.parse(options.studyData)
  65. console.log(data);
  66. this.pageData = {
  67. ...data
  68. }
  69. console.log(this.pageData);
  70. this.videoId = data.videoId
  71. this.jieName = data.jieName
  72. this.progressMarkers = data.progressMarkers
  73. this.getLive(); //获取播放凭证
  74. //uni.$on('playEnd', this.playEnd);
  75. },
  76. methods: {
  77. playEnd(data) {
  78. this.$refs.popupRef.open();
  79. },
  80. goBack() {
  81. this.$refs.popupRef.close();
  82. this.goUpPage()
  83. },
  84. goNext() {
  85. this.$refs.popupRef.close();
  86. toast("暂无此功能");
  87. this.goUpPage()
  88. return false
  89. },
  90. getLive() {
  91. let req = {
  92. videoId: this.videoId
  93. }
  94. getVideoAuth(req).then(res => {
  95. this.playAuth = res.data
  96. })
  97. },
  98. markersClick(data) {
  99. console.log(data)
  100. this.seekTime = data.offset
  101. },
  102. goUpPage() {
  103. // this.$refs.popupRef.open();
  104. uni.navigateTo({
  105. // url: `/pages/study/index?xueqi=${data.activeXueqi}&nianji=${data.activeNianji}&flag=selectGrades`
  106. url: `/pages/study/index?xueqi=${this.pageData.xueqi}&nianji=${this.pageData.nianji}&zhangId=${this.pageData.zhangId}`
  107. })
  108. }
  109. },
  110. created() {
  111. // console.log("getLive")
  112. // this.getLive(); //获取播放凭证
  113. },
  114. }
  115. </script>
  116. <script module="renderScript" lang="renderjs">
  117. export default {
  118. mounted() {
  119. console.log("renderScript1")
  120. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  121. this.loadWebPlayerSDK()
  122. },
  123. data() {
  124. return {
  125. player: null,
  126. playAuth: '',
  127. progressMarkers: [],
  128. seekTime: ''
  129. }
  130. },
  131. methods: {
  132. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  133. // console.log('service层中的options发生变化')
  134. // console.log('新值', newValue)
  135. // console.log('旧值', oldValue)
  136. // ownerInstance和this.$ownerInstance一样,可用来向service层通信
  137. // instance和ownerInstance的区别是:
  138. // instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
  139. // instance的作用目前尚不明确,官方没有给出用法
  140. if (newValue) {
  141. this.playAuth = newValue
  142. this.playAli()
  143. }
  144. },
  145. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  146. if (newValue) {
  147. this.progressMarkers = newValue
  148. }
  149. },
  150. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  151. if (newValue) {
  152. console.log(newValue, 'newValuenewValuenewValuenewValuenewValue')
  153. console.log(this.player.getStatus(), 'newValuenewValuenewValuenewValuenewValue')
  154. this.player.play()
  155. this.player.seek(newValue)
  156. // switch (this.player.getStatus()) {
  157. // case 'init':
  158. // break;
  159. // case 'ready':
  160. // break;
  161. // case 'loading':
  162. // this.player.play()
  163. // this.player.seek(newValue)
  164. // break;
  165. // case 'play':
  166. // this.player.seek(newValue)
  167. // break;
  168. // case 'pause':
  169. // this.player.play()
  170. // this.player.seek(newValue)
  171. // break;
  172. // case 'playing':
  173. // this.player.seek(newValue)
  174. // break;
  175. // case 'waiting':
  176. // break;
  177. // case 'error':
  178. // break;
  179. // case 'ended':
  180. // break;
  181. // default:
  182. // break;
  183. // }
  184. // this.player.seek(newValue)
  185. }
  186. },
  187. playAli() {
  188. let that = this
  189. //配置播放器
  190. var player = new Aliplayer({
  191. id: "wgy-player-test",
  192. "vid": 'b997f16cb9cb474cb93526cff77d8801',
  193. "playauth": this.playAuth,
  194. // "playConfig": {
  195. // "EncryptType": 'AliyunVoDEncryption'
  196. // },
  197. "qualitySort": "asc",
  198. "format": "m3u8",
  199. "mediaType": "video",
  200. "encryptType": 1,
  201. "progressMarkers": this.progressMarkers,
  202. "width": '100%',
  203. "height": '500px',
  204. "autoplay": false,
  205. "isLive": false,
  206. "rePlay": false,
  207. "playsinline": true,
  208. "preload": false,
  209. "controlBarVisibility": "hover",
  210. "useH5Prism": true
  211. }, function(player) {});
  212. this.player = player;
  213. player.one('canplay', function() {
  214. console.log('canplay', this.player.tag);
  215. player.tag.play();
  216. });
  217. player.on('ended', function() {
  218. that.$ownerInstance.callMethod('playEnd', {data:'end'})
  219. // uni.$emit('playEnd', {
  220. // data: 'end'
  221. // });
  222. });
  223. },
  224. loadWebPlayerSDK() {
  225. return new Promise((resolve, reject) => {
  226. const s_tag = document.createElement('script'); // 引入播放器js
  227. s_tag.type = 'text/javascript';
  228. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  229. s_tag.charset = 'utf-8';
  230. s_tag.onload = () => {
  231. // this.checkValue();
  232. resolve();
  233. }
  234. document.body.appendChild(s_tag);
  235. const l_tag = document.createElement('link'); // 引入播放器css
  236. l_tag.rel = 'stylesheet';
  237. l_tag.href =
  238. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  239. document.body.appendChild(l_tag);
  240. });
  241. },
  242. }
  243. }
  244. </script>