| | |
| | | <view |
| | | class="play-icon" |
| | | @click="togglePlay(index)" |
| | | v-if="currentVideoIsPlaying != null && !currentVideoIsPlaying" |
| | | v-if="!currentVideoIsPlaying" |
| | | > |
| | | <image src="/static/video/play.png" style="width: 45px;height: 45px" mode="aspectFit"></image> |
| | | </view> |
| | |
| | | playAt: 0 ,// 这个视频播放到哪了 |
| | | startPlayTime: 0 // 这个视频从什么时候开始播放的 |
| | | }, |
| | | currentVideoIsPlaying: null, // 当前视频是否正在播放 |
| | | currentVideoIsPlaying: true, // 当前视频是否正在播放 |
| | | isFullScreen: false, |
| | | windowHeight: 0, |
| | | currentIndex: 0, // 当前播放的视频索引 |
| | |
| | | } |
| | | }, |
| | | onShow() { |
| | | this.loadVideos() |
| | | // 如果视频按下暂停后切换页面再回到页面时,只算暂停时间(因为暂停时间和离开页面时间是重复的,只算一个) |
| | | if(this.startHidenTime !== 0 && this.currentVideoIsPlaying) { |
| | | const duration = Date.now() - this.startHidenTime |
| | |
| | | // 保存上一个视频的播放记录 |
| | | this.savePlayRecord() |
| | | const oldIndex = this.currentIndex; |
| | | console.log("视频上下文",this.videoContexts[oldIndex]); |
| | | this.currentIndex = e.detail.current; |
| | | |
| | | // 暂停上一个视频 |
| | | if (this.videoContexts[oldIndex]) { |
| | | this.videoContexts[oldIndex].pause(); |
| | | } |
| | | this.currentVideoIsPlaying = true; |
| | | |
| | | this.startPauseTime = 0; |
| | | // 播放当前视频 |
| | | if (this.videoContexts[this.currentIndex]) { |
| | |
| | | }, |
| | | // 视频播放事件 |
| | | onPlay(id, index) { |
| | | this.currentVideoIsPlaying = true; |
| | | console.log(id, index, "触发播放"); |
| | | if(index === this.currentIndex) { |
| | | this.currentVideoIsPlaying = true; |
| | | } else { |
| | | this.currentVideoIsPlaying = false; |
| | | return |
| | | } |
| | | this.playRecord.videoId = id; |
| | | // 没初始化才赋值,因为一个视频重复播放onPlay会重复触发 |
| | | if(this.playRecord.startPlayTime === 0) { |
| | |
| | | |
| | | // 视频暂停事件 |
| | | onPause(index) { |
| | | this.currentVideoIsPlaying = false; |
| | | console.log(index, "触发暂停"); |
| | | if(index === this.currentIndex) { |
| | | this.currentVideoIsPlaying = false; |
| | | } else { |
| | | this.currentVideoIsPlaying = true; |
| | | return |
| | | } |
| | | this.startPauseTime = Date.now() |
| | | }, |
| | | |