I am struggling with setting up the loop for youtube videos using youtube player api.
The problem is that the video is not running under a loop.
Here is my c
Since the html5 player, we can just right click on the video => play in loop.
From script, to replay at the end of the video:
document.getElementsByClassName('video-stream html5-main-video')[0].loop = true
Loop 1.66 seconds between two time points:
const video = document.getElementsByClassName('video-stream html5-main-video')[0]
/* Loop markers in seconds */
let start = 54.34, end = 56
/* Seek to time in seconds */
function seek(time){
video.loop = true
video.currentTime = time
video.play()
}
/* Loop between start and end */
function loop(e){
if (e.target.currentTime > end){
seek(start)
}
}
/* Will loop for 1.66s */
video.addEventListener("timeupdate", loop, false)
/* Seek to 54.34s */
seek(start)
/* Abort the loop */
// video.removeEventListener("timeupdate", loop, false)
/* New loop */
// start = 14; end = 15; seek(start)
Media events list
HTMLMediaElement reference