javascript - 如何在前后检查 HTML5 视频时间更新?
问题描述
我正在尝试检查 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>
解决方案
推荐阅读
- powershell - 提取多位信息并导出到报告中
- java - 如何每 5 秒在值之间切换 TextView
- docker - 从 Dockerfile 构建 Docker 映像导致错误“docker build”需要 1 个参数”
- python - Conda-forge 包构建失败:需要 CC,但即使添加了编译器也找不到
- joomla - 安装 Joomla 并安装扩展模块等,文件夹所有权有什么好的方法吗?
- java - 我们可以将“return”替换为“throw new Exception”吗?
- graphql - GraphQL 中的复杂查询变量(通过 Gatsby)
- ruby-on-rails - Rails active_storage:install 不会安装
- php - 单击图像时,它不会在 jQuery 中删除
- python-3.x - 抓取内部 div 的文本