I would like to build a small application running on browser ( using Chrome ) that synchronizes an embedded video with some graphics. I took inspiration from here https://www.youtube.com/watch?v=_AD2ciZ-0UI for a small test.
Here I am trying to play the video and "move" the position of a rectangle accordingly, in a synced way:
<!DOCTYPE html>
<html>
<body>
<video id="myvideo" width="400" controls>
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4"></source>
</video>
<svg id="myrect" viewBox="0 0 200 200" > <rect x=10 y=8 width=5 height=20
fill-opacity=0.0
style="stroke-width:0.5;stroke:rgb(0,0,0)"/> </svg>
<script>
var m = 10 ;
var myvideo = document.getElementById('myvideo')
var rect = document.getElementById('myrect');
myvideo.addEventListener('play', function() {
timerID=window.setInterval(function (){
m=parseInt(myvideo.currentTime);
console.log(m);
rect.setAttribute('x',m);
},100)
})
</script>
</body>
</html>
Unluckily, when running this I see that the variable "m" gets incremented correctly (looking at the values in the Console), but the rectangle is not moving. What am I doing wrong ?