I'm trying to set a time (seconds) for the video to get the frame in it. For some reason the currentTime is not working and when I assign it to the video and after when I get its value always return 0. I tried doing it with videojs and I have the same result. I read that might be "Accept-Ranges": "bytes" missing on the headers. You can check the Response/Request headers
![[here]](https://i.stack.imgur.com/3d0tX.png)
Here is the code:
var videoToFrame;
function GetVideoFrameForElement(elementId, path, seg = 0) {
if (videoToFrame != null) {
videoToFrame.currentTime = seg;
videoToFrame.onloadeddata = function (e) {};
videoToFrame.onseeked = function (e) {
var canvas = document.createElement('canvas');
canvas.height = videoToFrame.videoHeight;
canvas.width = videoToFrame.videoWidth;
var ctx = canvas.getContext('2d');
ctx.drawImage(videoToFrame, 0, 0, canvas.width, canvas.height);
var img = document.getElementById(elementId);
if (img != null) {
img.src = canvas.toDataURL();
console.log(videoToFrame.currentTime);
}
};
} else {
videoToFrame = document.createElement('video');
videoToFrame.crossOrigin = "anonymous";
videoToFrame.src = path;
videoToFrame.onloadeddata = function () {
this.currentTime = seg;
};
videoToFrame.onseeked = function (e) {
var canvas = document.createElement('canvas');
canvas.height = videoToFrame.videoHeight;
canvas.width = videoToFrame.videoWidth;
var ctx = canvas.getContext('2d');
ctx.drawImage(videoToFrame, 0, 0, canvas.width, canvas.height);
var img = document.getElementById(elementId);
if (img != null) {
img.src = canvas.toDataURL();
}
};
}
}