Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

532
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda