How to change HTML video playback rate when video is already playing?

222 views Asked by At

I am using Arduino/sensor generated data to alter a HTML video's playback rate.

function updateVideoPBR() {
  if ((inoData.distance/200) > 16) video_pbr = 16;
  else if ((inoData.distance/200) < 0.0625) video_pbr = 0.0625;
  else video_pbr = (inoData.distance/200)*16;
}

setInterval(() => {
  updateVideoPBR();
}, 50);

To read/write Arduino with JS I am using the Johnny-Five module. The data is then being transmitted from a local server to my browser client via socket.io.

When I refresh my localhost site in my browser the video playback rate is the value that the Arduino sent just that moment when I refreshed. All later changes made to video.playbackRate (in my case abbreviated as video_pbr) will not show any influence on the playbackrate when the video is already playing after I refreshed.

Is there any way to make sure the video's playback rate can be manipulated in a 'live'-manner, even when it was already started?

1

There are 1 answers

0
John F. Miller On

Setting the video_pbr variable is not enough. You need to communicate the new value over the wire to the browser. The best way to do that, IMHO, would be to make use of the WebSocket interface. You will need to check with your specific HTML / JavaScript library for how to make that work. If you need more help, try asking a specific question related to the JavaScript framework you are using.