I have the following interval
which updates the progress value while a YouTube video is playing. It works fine most of the cases but in some other cases the progress does weird things like going back and forth and I get the following error in the console.
NotSupportedError: DOM Exception 9: The implementation did not support the requested type of object or operation.
This occurs in all browsers and it mostly happens when I load a new video.
if(player) {
player.loadVideoById({'videoId': data.yt_id});
}
Does anyone know why is this happening and how can I fix this?
var value = 0;
var duration = player.getDuration();
var progress = document.getElementById('progress');
var to = setInterval(function() {
value = 1 / duration * player.getCurrentTime();
progress.value = value;
}, 250);
The error fires on: progress.value = value;
progress
is a <progress>
element.
console.log():
value: 0.02622895199857715
youtube.js:104 player.getCurrentTime(): 5.417367
youtube.js:103 value: 0.02746555095910624
youtube.js:104 player.getCurrentTime(): 5.672776
youtube.js:103 value: 0.02870214991963533
youtube.js:104 player.getCurrentTime(): 5.928185
youtube.js:103 value: 0.029826330792843594
youtube.js:104 player.getCurrentTime(): 6.160375