获取并设置HTML5视频当前时间

Last week I explored how you could get the duration of a HTML5 video.  It's an important technique, obviously, but one that may be a bit more important is managing the video's time setting.  Both setting and getting the video's time is important when creating a chrome around the video, so let's review how to accomplish this feat.

上周,我探讨了如何获取HTML5视频的时长 。 显然,这是一项重要的技术,但可能更重要的一项是管理视频的时间设置。 在视频周围创建镶边时,设置和获取视频时间都很重要,因此让我们回顾一下如何实现这一壮举。

The first and probably most important part of managing video time state is knowing that video currentTime is the important attribute.  You can retrieve the video's current time with the following:

管理视频时间状态的第一个也是最重要的部分是知道视频currentTime是重要属性。 您可以使用以下方法检索视频的当前时间:


// https://www.youtube.com/watch?v=Cwkej79U3ek
console.log(video.currentTime);  // 25.431747


currentTime acts as both a getter and a setter, so you can move about the video by setting a value to currentTime:

currentTime既充当获取器,也充当设置器,因此您可以通过将值设置为currentTime来移动视频:


video.currentTime = 0; // Restart


The API is easy enough and the property is self-explanatory.  You'll still need to do the "second" math to interpret the time, both inward and outward, but the second unit is as fair as you could expect, so this API is one to be appreciated.

该API非常简单,并且该属性不言自明。 您仍然需要做“第二”数学来解释时间的向内和向外,但是第二个单元正如您期望的那样公平,因此此API是值得赞赏的。

翻译自: https://davidwalsh.name/html5-video-current-time

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值