我试图在视频播放时获得寻道时间。我使用播放事件只触发视频开始。
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);
});
答案 0 :(得分:2)
来自MDN:
HTMLMediaElement.currentTime
属性提供当前播放 时间以秒为单位。设置此值会将媒体搜索到新的时间。
根据这些信息,您应该执行以下操作:
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);
});
答案 1 :(得分:1)
secondvideo.addEventListener("timeupdate",
function (ev) {
console.log(ev.target.currentTime);
});
https://www.w3.org/TR/html5/embedded-content-0.html#handler-mediacontroller-ontimeupdate
您可以在此处找到HTML5视频事件和API:https://www.w3.org/2010/05/video/mediaevents.html