最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to get the the seek time while on video playing in javascript - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 5
secondvideo.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);
});
发布评论

评论列表(0)

  1. 暂无评论