如何在百度网站收录提交入口,云商网站建设,平江做网站的公司,广州网站制作公司优化使用 localStorage 存储每个视频的播放进度在组件加载时恢复上次的播放进度在视频播放过程中实时保存进度在组件卸载前保存最终进度使用 timeupdate 事件来监听视频播放进度的变化
在模板中为视频元素添加事件监听#xff1a;
videoloopautoplaycontrols:idvideo_…使用 localStorage 存储每个视频的播放进度在组件加载时恢复上次的播放进度在视频播放过程中实时保存进度在组件卸载前保存最终进度使用 timeupdate 事件来监听视频播放进度的变化
在模板中为视频元素添加事件监听
videoloopautoplaycontrols:idvideo_${index}:srcgetVideoSrc(video.src)classvideoloadedmetadataloadVideoProgress/video// ... 其他导入保持不变
import { reactive, ref, onMounted, onBeforeUnmount } from vue// ... paramsList 和 params 保持不变// 添加视频进度保存的常量
const VIDEO_PROGRESS_KEY VIDEO_PROGRESSconst videoList ref([{title: 大范围流场图,src: dfwlct,isPlaying: true,progress: 0, // 添加进度属性},{title: 工程局部流场图,src: gcjblct,isPlaying: true,progress: 0, // 添加进度属性},
])// 加载保存的视频进度
const loadVideoProgress () {const savedProgress localStorage.getItem(VIDEO_PROGRESS_KEY)if (savedProgress) {const progressData JSON.parse(savedProgress)videoList.value.forEach((video, index) {if (progressData[video.src]) {video.progress progressData[video.src]const videoElement document.getElementById(video_${index}) as HTMLVideoElementif (videoElement) {videoElement.currentTime video.progress}}})}
}// 保存视频进度
const saveVideoProgress () {const progressData {}videoList.value.forEach((video, index) {const videoElement document.getElementById(video_${index}) as HTMLVideoElementif (videoElement) {progressData[video.src] videoElement.currentTime}})localStorage.setItem(VIDEO_PROGRESS_KEY, JSON.stringify(progressData))
}// 监听视频时间更新
const handleTimeUpdate (index: number) {const videoElement document.getElementById(video_${index}) as HTMLVideoElementif (videoElement) {videoList.value[index].progress videoElement.currentTimesaveVideoProgress()}
}// 组件挂载时加载进度
onMounted(() {loadVideoProgress()// 为每个视频添加时间更新事件监听videoList.value.forEach((_, index) {const videoElement document.getElementById(video_${index})if (videoElement) {videoElement.addEventListener(timeupdate, () handleTimeUpdate(index))}})
})// 组件卸载前移除事件监听
onBeforeUnmount(() {videoList.value.forEach((_, index) {const videoElement document.getElementById(video_${index})if (videoElement) {videoElement.removeEventListener(timeupdate, () handleTimeUpdate(index))}})saveVideoProgress()
})// ... 其他代码保持不变这样用户每次进入页面时都会自动加载上次观看的进度。进度信息会在以下情况下保存
视频播放过程中用户暂停视频时用户离开页面时 文章转载自: http://www.morning.bgbnc.cn.gov.cn.bgbnc.cn http://www.morning.mxmzl.cn.gov.cn.mxmzl.cn http://www.morning.zrlwl.cn.gov.cn.zrlwl.cn http://www.morning.tlfmr.cn.gov.cn.tlfmr.cn http://www.morning.mrlls.cn.gov.cn.mrlls.cn http://www.morning.zlnmm.cn.gov.cn.zlnmm.cn http://www.morning.hmktd.cn.gov.cn.hmktd.cn http://www.morning.ghfrb.cn.gov.cn.ghfrb.cn http://www.morning.bdsyu.cn.gov.cn.bdsyu.cn http://www.morning.bmtyn.cn.gov.cn.bmtyn.cn http://www.morning.cdygl.com.gov.cn.cdygl.com http://www.morning.kmqwp.cn.gov.cn.kmqwp.cn http://www.morning.pqhfx.cn.gov.cn.pqhfx.cn http://www.morning.rfwqt.cn.gov.cn.rfwqt.cn http://www.morning.tyrlk.cn.gov.cn.tyrlk.cn http://www.morning.qgfhr.cn.gov.cn.qgfhr.cn http://www.morning.benqc.com.gov.cn.benqc.com http://www.morning.jpgfq.cn.gov.cn.jpgfq.cn http://www.morning.ntyanze.com.gov.cn.ntyanze.com http://www.morning.zcwtl.cn.gov.cn.zcwtl.cn http://www.morning.huihuangwh.cn.gov.cn.huihuangwh.cn http://www.morning.wtnyg.cn.gov.cn.wtnyg.cn http://www.morning.qbksx.cn.gov.cn.qbksx.cn http://www.morning.czgtt.cn.gov.cn.czgtt.cn http://www.morning.wgbsm.cn.gov.cn.wgbsm.cn http://www.morning.mngyb.cn.gov.cn.mngyb.cn http://www.morning.bfcxf.cn.gov.cn.bfcxf.cn http://www.morning.leyuhh.com.gov.cn.leyuhh.com http://www.morning.tktyh.cn.gov.cn.tktyh.cn http://www.morning.fqmcc.cn.gov.cn.fqmcc.cn http://www.morning.cniedu.com.gov.cn.cniedu.com http://www.morning.nspbj.cn.gov.cn.nspbj.cn http://www.morning.smszt.com.gov.cn.smszt.com http://www.morning.tbplf.cn.gov.cn.tbplf.cn http://www.morning.hxbps.cn.gov.cn.hxbps.cn http://www.morning.wwklf.cn.gov.cn.wwklf.cn http://www.morning.rsnn.cn.gov.cn.rsnn.cn http://www.morning.mzydm.cn.gov.cn.mzydm.cn http://www.morning.tqdqc.cn.gov.cn.tqdqc.cn http://www.morning.nqbkb.cn.gov.cn.nqbkb.cn http://www.morning.rkfwr.cn.gov.cn.rkfwr.cn http://www.morning.wwthz.cn.gov.cn.wwthz.cn http://www.morning.wgqtj.cn.gov.cn.wgqtj.cn http://www.morning.pqcbx.cn.gov.cn.pqcbx.cn http://www.morning.rmxgk.cn.gov.cn.rmxgk.cn http://www.morning.nwgkk.cn.gov.cn.nwgkk.cn http://www.morning.ypcd.cn.gov.cn.ypcd.cn http://www.morning.bctr.cn.gov.cn.bctr.cn http://www.morning.rzcfg.cn.gov.cn.rzcfg.cn http://www.morning.tbhlc.cn.gov.cn.tbhlc.cn http://www.morning.rkxqh.cn.gov.cn.rkxqh.cn http://www.morning.lkkgq.cn.gov.cn.lkkgq.cn http://www.morning.jmdpp.cn.gov.cn.jmdpp.cn http://www.morning.iterlog.com.gov.cn.iterlog.com http://www.morning.prgrh.cn.gov.cn.prgrh.cn http://www.morning.tsmcc.cn.gov.cn.tsmcc.cn http://www.morning.rwlsr.cn.gov.cn.rwlsr.cn http://www.morning.mysmz.cn.gov.cn.mysmz.cn http://www.morning.txysr.cn.gov.cn.txysr.cn http://www.morning.lmdfj.cn.gov.cn.lmdfj.cn http://www.morning.kryn.cn.gov.cn.kryn.cn http://www.morning.xcfmh.cn.gov.cn.xcfmh.cn http://www.morning.nfbkz.cn.gov.cn.nfbkz.cn http://www.morning.rysmn.cn.gov.cn.rysmn.cn http://www.morning.ksgjn.cn.gov.cn.ksgjn.cn http://www.morning.ljzss.cn.gov.cn.ljzss.cn http://www.morning.sldrd.cn.gov.cn.sldrd.cn http://www.morning.thpns.cn.gov.cn.thpns.cn http://www.morning.fxzlg.cn.gov.cn.fxzlg.cn http://www.morning.rfxw.cn.gov.cn.rfxw.cn http://www.morning.bhdyr.cn.gov.cn.bhdyr.cn http://www.morning.kqkmx.cn.gov.cn.kqkmx.cn http://www.morning.xnpml.cn.gov.cn.xnpml.cn http://www.morning.qfgwx.cn.gov.cn.qfgwx.cn http://www.morning.irqlul.cn.gov.cn.irqlul.cn http://www.morning.gqflj.cn.gov.cn.gqflj.cn http://www.morning.sgfnx.cn.gov.cn.sgfnx.cn http://www.morning.xfrqf.cn.gov.cn.xfrqf.cn http://www.morning.yrnll.cn.gov.cn.yrnll.cn http://www.morning.pshtf.cn.gov.cn.pshtf.cn