假设我们的应用程序在Safari上使用默认的视频播放器.
当用户播放视频,然后试图使用搜索栏移动到视频的不同位置时,似乎首先触发了pause
个事件,然后我们将触发seeking
和seeked
个事件.
I am wondering if we can get the 100 value prior to the seek.例如,假设用户使用搜索栏从t = 7
跳到t = 42
,我想以某种方式得到7
作为currentTime
值.
我希望我们可以通过访问pause
事件处理程序中的currentTime
属性来获得这个值,pause
事件处理程序在查找之后立即调用,如下所示:
const video = document.querySelector('#myvideo');
video.addEventListener('pause', () => {
// I expected that the `video.currentTime` here has the "previous" position,
// but it already points to the new position
console.log(video.currentTime);
});
但不幸的是,当时currentValue
已经更新为新值.
有什么好方法可以实现吗?
(编辑)
<!DOCTYPE html>
<html>
<body>
<video
id="myvideo"
width="640"
height="360"
controls
src="video.mp4"
></video>
</body>
<script>
const video = document.querySelector("#myvideo");
let cache = 0;
video.addEventListener("timeupdate", () => {
cache = video.currentTime;
});
video.addEventListener("pause", () => {
console.log({ cache, currentTime: video.currentTime });
});
</script>
</html>