Last week translated an article: How to get the duration of a HTML5 video. Obviously this is a simple but practical technology, but I think there is a more important point of knowledge is to control the video time settings. Setting (setting) and acquiring (getting) time are useful when working with HTML5 technology, so let's take a look at how to achieve this goal!
When it comes to managing video status, it's important to understand currentTime
what a ghost is. You can use this property to get to which point in time you are currently playing:
// https://www.youtube.com/watch?v=Cwkej79U3ekconsole.log(video.currentTime); // 25.431747
currentTime
Both getter and setter properties, so you can set the currentTime
value directly to control the playback progress:
video.currentTime = 0; // Restart
API interfaces are easy to understand and self-explanatory (self-explanatory). You still need to deal with "second" to specify the time, including the actual and external display (both inward and outward), but seconds (second) This unit is as fair as you expect, so this API design is very ingenious.
Examples can refer to the Xiaomi Air Purifier Demo page: http://www.mi.com/air/
<video id="videoIntro" class="video" data-video-name="intro" poster="http://c1.mifile.cn/f/i/2014/cn/goods/air/overall/video-main-poster.jpg" style="height: 600px; width: 800px; display: none;"> <source type="video/mp4" src="http://c1.mifile.cn/f/i/2014/cn/goods/air/overall/video-intro.mp4?2014120901"> <source type="video/webm" src="http://c1.mifile.cn/f/i/2014/cn/goods/air/overall/video-intro.webm?2014120901"></video>
In addition, the Apple website demo also uses this kind of control mode.
Original link: http://davidwalsh.name/html5-video-current-time
Original date: March 16, 2015
Translation Date: March 21, 2015
Translators: Anchor Http://blog.csdn.net/renfufei
Get and set the current progress of HTML5 video