basicTrainingDetails - 副本.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view>
  3. <!-- <video id="vid"><source :src="details.videoUrl"></video> -->
  4. <!-- <video width="320" height="240" controls="controls" preload="auto">
  5. <source src="static/img/11111.mp4" type="video/mp4">
  6. 您的浏览器不支持Video标签。
  7. </video> -->
  8. <!-- <video @timeupdate="updateTime" @canplay="getDuration" ref="video111" :src="details.videoUrl" controls="controls" preload="auto"></video> -->
  9. <!-- <view id="player" style="width: 100%;"></view> -->
  10. <video id="myVideo" @timeupdate="timeUpdate" :src="url" controls initial-time="initial_time" />
  11. <u-button @click="changeRate">切换</u-button>
  12. <u-parse :html="details.content" class="f-padding"></u-parse>
  13. </view>
  14. </template>
  15. <script>
  16. import Player from 'xgplayer';
  17. export default{
  18. data(){
  19. return{
  20. videoContext: uni.createVideoContext('myVideo', this),
  21. id:'',
  22. content:'',
  23. details:{},
  24. duration:'',
  25. url: "http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400",
  26. video_real_time: 0, //实时播放进度
  27. nitial_time: '', //视频跳转进度 秒
  28. }
  29. },
  30. onLoad(page){
  31. console.log(page)
  32. this.id = page.id;
  33. this.getAdaptTrainOnlineDetails(this.id);
  34. this.initial_time = '0'
  35. },
  36. onShow(){
  37. },
  38. methods:{
  39. getAdaptTrainOnlineDetails(id){
  40. this.$u.api.getAdaptTrainOnlineDetails({id:id}).then(res=>{
  41. this.details = res.data;
  42. let player = new Player({
  43. id: 'player',
  44. autoplay: false,
  45. playsinline: true,
  46. url: this.details.videoUrl,
  47. "screenShot": true,
  48. fluid: true,
  49. videoInit: true,
  50. enableVideoDbltouch: true,
  51. });
  52. player.once('ended',()=>{
  53. this.upAdaptTrainOnlineInfo();
  54. });
  55. player.once('canplay',(e)=>{
  56. console.log('canplay',player.duration)
  57. this.duration = player.duration;
  58. });
  59. player.on('timeupdate',()=>{
  60. let that = this;
  61. // console.log('that',that);
  62. // console.log('currentTime',player.currentTime);
  63. // // setInterval(that.aaa+=1,1000)
  64. // console.log('that.aaa',that.aaa);
  65. //事件名称可以在上述查询
  66. });
  67. console.log('getAdaptTrainOnline',JSON.parse(JSON.stringify(res)));
  68. })
  69. },
  70. upAdaptTrainOnlineInfo(){
  71. let params ={
  72. tabId:this.details.id,
  73. adaptName:this.details.adaptName,
  74. url:this.details.videoUrl,
  75. type:this.details.videoType,
  76. duration:this.duration,
  77. playDuration:this.duration,
  78. }
  79. this.$u.api.upAdaptTrainOnlineInfo(params).then(res=>{
  80. this.rate = res.data;
  81. console.log('upAdaptTrainOnlineInfo',JSON.parse(JSON.stringify(res)));
  82. })
  83. },
  84. timeUpdate(e) {
  85. var isReady = 1; // 是否开启可以视频快进 1 禁止开启
  86. //跳转到指定播放位置 initial-time 时间为秒
  87. let that = this;
  88. //播放的总时长
  89. var duration = e.detail.duration
  90. //实时播放进度 秒数
  91. var currentTime = parseInt(e.detail.currentTime)
  92. //当前视频进度
  93. // console.log("视频播放到第" + currentTime + "秒")//查看正在播放时间,以秒为单位
  94. if (that.video_real_time == 0){
  95. var jump_time = parseInt(that.initial_time) + parseInt(that.video_real_time)
  96. } else {
  97. var jump_time = parseInt(that.video_real_time)
  98. }
  99. if(isReady==1){
  100. if (currentTime > jump_time && currentTime - jump_time>3){
  101. let videoContext = wx.createVideoContext('myVideo')
  102. videoContext.seek(that.video_real_time)
  103. wx.showToast({
  104. title: '未完整看完该视频,不能快进',
  105. icon: 'none',
  106. duration: 2000,
  107. })
  108. }
  109. }
  110. that.video_real_time = currentTime //实时播放进度
  111. },
  112. changeRate() {
  113. this.videoContext.playbackRate(2.0)
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. #player{margin-bottom: 24rpx;}
  120. // @import './basicTrainingDetails.scss'
  121. #myVideo {
  122. width: 100%;
  123. }
  124. </style>