Reputation: 749
I'd like to set up the button. Then if I hit that, the video will be starting at the position 30 secs elapsed. How can I code that?
My current code is just like this
<video id="video" controls="controls" autoplay="autoplay" name="media"><source src="video.mp4" type="video/mp4"></video>
<button name="test" onclick="alert(Math.floor(document.getElementById('video').currentTime) + ' secs elapsed!');">How much time has already elapsed?</button>
Upvotes: 0
Views: 188
Reputation: 34895
You can seek to a particular section of the HTML5 Video using its currentTime
property:
JavaScript:
document.getElementsByName('test')[0].onclick = function () {
document.getElementById('video').currentTime = 120; // seeks to the 2nd minute
}
Upvotes: 1