1.想要让视频前进或后退,首先得知道现在播放到哪
//视频播放到那一秒
timeupdate(e){
console.log(e.detail.currentTime,"eee");
this.nowSecond = e.detail.currentTime //nowSecond是自己定义的参数
},
<video
id="myVideo"
:src="videoSrc"
binderror="videoErrorCallback"
:muted = "muted"
show-center-play-btn='true'
show-play-btn="false"
controls = "true"
picture-in-picture-mode="['push', 'pop']"
bindenterpictureinpicture='bindVideoEnterPictureInPicture'
bindleavepictureinpicture='bindVideoLeavePictureInPicture'
@play="onPlay"
@pause="onPause"
@ended="onEnded"
@timeupdate = "timeupdate"
style="width: 100%;height: 402rpx;"
play-btn-position="center"
></video>
@timeupdate = "timeupdate"中timeupdate是video自带的一个属性
可以打印一下e.detail.currentTime,每隔250ms打印一下视频现在播放的位置
这个方法就获取到了当前播放的位置、
2.快进和后退5s
点击快进图标添加一点击时间
//快进5s
rightEvent(){
const videoContext = uni.createVideoContext('myVideo');
videoContext.seek(this.nowSecond + 5); // 将视频回退 5 秒
}
先获取到这个视频,myVideo是视频的id
const videoContext = uni.createVideoContext('myVideo');
接着通过seek更改视频播放到第几秒
设置到当前秒数+5秒,后退就是-5秒