lookShipin.vue 7.0 KB

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