I have a fairly simple iteration that copies the content of a <video>
into a <canvas>
. The idea is that I start copying when the video plays and stops copying when it detects that the video has stopped playing (whether via ending or when paused).
play() {
this.video.play()
this.watch()
}
watch(previous = -1) {
requestAnimationFrame(() => {
const current = this.video.currentTime
this.ctx.drawImage(...)
if(current != previous) {
this.watch(current)
console.dir({ current, previous })
} else {
console.error({ current, previous })
}
})
}
If there is no current != previous
check, the video copies fine, but it obviously doesn't ever stop copying. If the check is in place, the output reports that the first iteration is different (previous == -1
and current == 0
). But the second loop through (which is in the requestAnimationFrame
callback) has previous == 0
and also current == 0
, so the loop stops.
I don't understand why currentTime
is not advancing. I've called play()
on the video, so it should be playing, especially be the time the next animation frame comes around. I've also tried making watch()
the listener for the video
's play
event, which didn't make a difference.