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

250
Views
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 answers
Answer question

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 Report
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!