Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

246
Vistas
How can I get current time of autoplayed html5 mp4 video in javascript and then stop it when time reaches for lets say 5 seconds?

So, I need to autoplay couple of videos with same class on page load. That is fine. Then, when videos starts playing, when they reach for 1 second, I need them to stop automatically. The other part is what I need.

 <video playsinline muted loop class="video">
     <source src="video-source">
 </video>

let videos = document.querySelectorAll('.video');

window.addEventListener('DOMContentLoaded', () => {
   videos.forEach(el => {
    el.play();
   });
 });

I have tried doing something like this, get currentTime and then make an IF statement but no luck. It always console loggs 0.

  function myFunction() {
   videos.forEach(el => {
   console.log(el.currentTime);
   if(el.currentTime = 5) {
   el.pause();     
  }
});

}

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The issue you will have with your current attempt is that it only runs once, you need to have a way of checking your logic at intervals so that you can continuously check the time lapsed.

You could potentially look at using the timeupdate video event, this runs repeatedly whilst a video is playing.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda