I'm trying to get the seek time while on video playing. I use the play event it is triggered only video start.
HTML:
<video controls id="videoFile">
<source src="Why Linux over Windows 3D Animation.mp4" id="video_here">
</video>
Javasript:
var secondvideo = document.getElementById('videoFile');
secondvideo.addEventListener('play', function(e) {
// The video is playing
console.log("current time= "+ document.getElementById('videoFile').currentTime);
});
I'm trying to get the seek time while on video playing. I use the play event it is triggered only video start.
HTML:
<video controls id="videoFile">
<source src="Why Linux over Windows 3D Animation.mp4" id="video_here">
</video>
Javasript:
var secondvideo = document.getElementById('videoFile');
secondvideo.addEventListener('play', function(e) {
// The video is playing
console.log("current time= "+ document.getElementById('videoFile').currentTime);
});
Share
Improve this question
edited Sep 21, 2017 at 3:49
santho
asked Sep 19, 2017 at 8:59
santhosantho
3862 silver badges16 bronze badges
4
- docs.videojs./docs/api/player.html#MethodscurrentTime – Unknown_Coder Commented Sep 19, 2017 at 9:02
- I want the event name to get the seek time while on video playing. – santho Commented Sep 19, 2017 at 9:07
- 2 Here you can find HTML5 Video Events and API: w3/2010/05/video/mediaevents.html – parameciostudio Commented Sep 19, 2017 at 9:09
- Thank you so much. – santho Commented Sep 19, 2017 at 9:12
2 Answers
Reset to default 5secondvideo.addEventListener("timeupdate",
function (ev) {
console.log(ev.target.currentTime);
});
https://www.w3/TR/html5/embedded-content-0.html#handler-mediacontroller-ontimeupdate
Here you can find HTML5 Video Events and API: https://www.w3/2010/05/video/mediaevents.html
From MDN:
The
HTMLMediaElement.currentTime
property gives the current playback time in seconds. Setting this value seeks the media to the new time.
Based on this information, you should do something like the following:
var secondvideo = document.getElementById('videoFile');
secondvideo.addEventListener('play', function(e) {
// The video is playing
console.log("Playing video");
console.log(secondvideo.currentTime);
});
secondvideo.addEventListener('pause', function(e) {
// The video is paused
console.log("Paused video");
console.log(secondvideo.currentTime);
});
secondvideo.addEventListener('seeking', function(e) {
// The user seeked a new timestamp in playback
console.log("Seeking in video");
console.log(secondvideo.currentTime);
});