Skip to content

Instantly share code, notes, and snippets.

@RecuencoJones
Last active March 26, 2020 18:00
Show Gist options
  • Save RecuencoJones/763338ab3d98c9035589a65d62ccf59e to your computer and use it in GitHub Desktop.
Save RecuencoJones/763338ab3d98c9035589a65d62ccf59e to your computer and use it in GitHub Desktop.
Youtube Video Looper
function loop(video, loopStart, loopEnd) {
function _check() {
if (video.currentTime >= loopEnd) {
video.currentTime = loopStart;
}
}
const interval = window.setInterval(_check, 50);
return () => window.clearInterval(interval);
}
const video = document.querySelector('.html5-main-video');
// loop one minute
// call stop() once done ;)
const stop = loop(video, 60, 120);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment