lookShipin.vue 6.6 KB

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