gpt4 book ai didi

javascript - 如何查看HTML5视频时间更新前后?

转载 作者:行者123 更新时间:2023-11-29 23:20:25 24 4
gpt4 key购买 nike

我正在尝试检查 HTML5 中视频的当前播放时间更改。我目前正在使用 seeking 事件来检查当前播放时间是否已更改。但我想知道时间更改为多长时间以及之前的时间在哪里。

如果有人不能正确理解问题,请在下方评论。

我的代码:

<html>
<body>

<video id="myVideo" width="320" height="176" controls>
<source src="https://www.w3schools.com/tags/mov_bbb.mp4" type="video/mp4">
</video>

<p>Playback position NOW: <span id="pos1"></span> | This should show the duration the video is at after 'seeking' event</p>
<p>Playback position BEFORE: <span id="pos2"></span> | This should show the duration the video was at after 'seeking' event</p>

<script>
var vid = document.getElementById("myVideo");
vid.addEventListener("seeking", function(){before(vid.currentTime);});
vid.addEventListener('seeked', after);

function before(time)
{
document.getElementById("pos1").innerHTML = time;
}
function after()
{
document.getElementById("pos2").innerHTML = vid.currentTime;
}
</script>

</body>
</html>

最佳答案

我建议同时查看 seekingseeked事件。也许通过在开始搜索时找到 currentTime,然后在触发 seeked 时再次找到它,您可以输出这两个时间。

关于javascript - 如何查看HTML5视频时间更新前后?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50893443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com