我正在尝试在 js 中获取当前时间的视频。我想出了一个相当丑陋且不太精确的解决方案,使用setInterval
on the play
event。但我非常喜欢使用更好的方法。也许requestAnimationFrame
可以做到吗?我愿意寻求更好的解决方案。
当前代码:
this.video = document.createElement('video')
this.duration = null
this.currentTime = null
this.video.addEventListener('play', this.play)
play(e) {
setInterval(() => {
this.currentTime = this.video.currentTime
}, 1000)
}
我认为您正在寻找的是
timeupdate
事件。例子: