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

181
Visualizações
How can I determine the width and height of a video without going through the DOM?

If I want to determine the width and height of an image, I can do the following:

let image = new Image();
image.src = ...the source ;
image.decode();

console.log( image.width, image.height );

There is no need to create a DOM element to render the image and then obtain the the dimensions.

Is it possible to do something similar with a video? If so, how?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This seems to do what I want:

let video = document.createElement( 'video');

video.setAttribute( "preload", "metadata" );

video.src = // ...the data source

video.addEventListener( 'loadeddata', function() {
    console.log( this.videoWidth, this.videoHeight );

});

I create the video element, but do not insert it into the DOM. I believe setting the preload attribute does not require the entire video file to be loaded, but I am not certain about that.

The data is loaded and the loadeddata event is triggered, logging the width and height of the video.

I would be interested in knowing what other people thought about this solution.

about 4 years ago · Juan Pablo Isaza Relatório
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