lookShipin.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. return false
  88. },
  89. getLive() {
  90. let req = {
  91. videoId: this.videoId
  92. }
  93. getVideoAuth(req).then(res => {
  94. this.playAuth = res.data
  95. })
  96. },
  97. markersClick(data) {
  98. console.log(data)
  99. this.seekTime = data.offset
  100. },
  101. goUpPage() {
  102. // this.$refs.popupRef.open();
  103. uni.navigateTo({
  104. // url: `/pages/study/index?xueqi=${data.activeXueqi}&nianji=${data.activeNianji}&flag=selectGrades`
  105. url: `/pages/study/index?xueqi=${this.pageData.xueqi}&nianji=${this.pageData.nianji}&zhangId=${this.pageData.zhangId}`
  106. })
  107. }
  108. },
  109. created() {
  110. // console.log("getLive")
  111. // this.getLive(); //获取播放凭证
  112. },
  113. }
  114. </script>
  115. <script module="renderScript" lang="renderjs">
  116. export default {
  117. mounted() {
  118. console.log("renderScript1")
  119. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  120. this.loadWebPlayerSDK()
  121. },
  122. data() {
  123. return {
  124. player: null,
  125. playAuth: '',
  126. progressMarkers: [],
  127. seekTime: ''
  128. }
  129. },
  130. methods: {
  131. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  132. // console.log('service层中的options发生变化')
  133. // console.log('新值', newValue)
  134. // console.log('旧值', oldValue)
  135. // ownerInstance和this.$ownerInstance一样,可用来向service层通信
  136. // instance和ownerInstance的区别是:
  137. // instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
  138. // instance的作用目前尚不明确,官方没有给出用法
  139. if (newValue) {
  140. this.playAuth = newValue
  141. this.playAli()
  142. }
  143. },
  144. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  145. if (newValue) {
  146. this.progressMarkers = newValue
  147. }
  148. },
  149. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  150. if (newValue) {
  151. console.log(newValue, 'newValuenewValuenewValuenewValuenewValue')
  152. console.log(this.player.getStatus(), 'newValuenewValuenewValuenewValuenewValue')
  153. this.player.play()
  154. this.player.seek(newValue)
  155. // switch (this.player.getStatus()) {
  156. // case 'init':
  157. // break;
  158. // case 'ready':
  159. // break;
  160. // case 'loading':
  161. // this.player.play()
  162. // this.player.seek(newValue)
  163. // break;
  164. // case 'play':
  165. // this.player.seek(newValue)
  166. // break;
  167. // case 'pause':
  168. // this.player.play()
  169. // this.player.seek(newValue)
  170. // break;
  171. // case 'playing':
  172. // this.player.seek(newValue)
  173. // break;
  174. // case 'waiting':
  175. // break;
  176. // case 'error':
  177. // break;
  178. // case 'ended':
  179. // break;
  180. // default:
  181. // break;
  182. // }
  183. // this.player.seek(newValue)
  184. }
  185. },
  186. playAli() {
  187. let that = this
  188. //配置播放器
  189. var player = new Aliplayer({
  190. id: "wgy-player-test",
  191. "vid": 'b997f16cb9cb474cb93526cff77d8801',
  192. "playauth": this.playAuth,
  193. // "playConfig": {
  194. // "EncryptType": 'AliyunVoDEncryption'
  195. // },
  196. "qualitySort": "asc",
  197. "format": "m3u8",
  198. "mediaType": "video",
  199. "encryptType": 1,
  200. "progressMarkers": this.progressMarkers,
  201. "width": '100%',
  202. "height": '500px',
  203. "autoplay": false,
  204. "isLive": false,
  205. "rePlay": false,
  206. "playsinline": true,
  207. "preload": false,
  208. "controlBarVisibility": "hover",
  209. "useH5Prism": true
  210. }, function(player) {});
  211. this.player = player;
  212. player.one('canplay', function() {
  213. console.log('canplay', this.player.tag);
  214. player.tag.play();
  215. });
  216. player.on('ended', function() {
  217. that.$ownerInstance.callMethod('playEnd', {data:'end'})
  218. // uni.$emit('playEnd', {
  219. // data: 'end'
  220. // });
  221. });
  222. },
  223. loadWebPlayerSDK() {
  224. return new Promise((resolve, reject) => {
  225. const s_tag = document.createElement('script'); // 引入播放器js
  226. s_tag.type = 'text/javascript';
  227. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  228. s_tag.charset = 'utf-8';
  229. s_tag.onload = () => {
  230. // this.checkValue();
  231. resolve();
  232. }
  233. document.body.appendChild(s_tag);
  234. const l_tag = document.createElement('link'); // 引入播放器css
  235. l_tag.rel = 'stylesheet';
  236. l_tag.href =
  237. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  238. document.body.appendChild(l_tag);
  239. });
  240. },
  241. }
  242. }
  243. </script>