Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

529
Views
Javascript: video.currentTime = value not working

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]

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();
            }
        };
    }
}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!