html:
<video :poster="url + cover" id="myVideo" :title="data.course_title" enable-progress-gesture="false" show-loading="true" show-center-play-btn="true" vslide-gesture="true" show-mute-btn="true" enable-play-gesture="true" auto-pause-if-navigate="true" vslide-gesture-in-fullscreen="true" auto-pause-if-open-native="true" :initial-time="videoContext" style="width: 100%;" :src="data.video_url" controls @timeupdate="videoTimeUpdateEvent">></video>
js:
export default { data() { return { data: [], //数据 url: getApp().globalData.url, //域名 currentTime: '', //现在的时长 durationTime: '', //总时长 jilu: [], //记录 status: false, videoContext: 0, watch: 0, //用来判断是否快进 box: null, cover: '' } }, onHide() { this.box.pause() }, onLoad() { this.cover = uni.getStorageSync('cover').url }, onReady() { this.box = uni.createVideoContext('myVideo') }, methods: { videoTimeUpdateEvent(e) { this.currentTime = Number(e.detail.currentTime); if (this.currentTime - this.watch > 10) { uni.showToast({ title: '不能快进', icon: 'none' }) this.box.seek(this.watch) this.videoContext = this.watch } else { this.watch = this.currentTime } }, }