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