I know that I can infinitely loop a video using the "loop" attribute. But can I limit the number of video cycles to 5 times?
You will need to use JavaScript for this. Take a look at the snippet below:
var iterations = 1; document.getElementById('iteration').innerText = iterations; myVideo.addEventListener('ended', function () { if (iterations < 5) { this.currentTime = 0; this.play(); iterations ++; document.getElementById('iteration').innerText = iterations; } }, false);
<div>Iteration: <span id="iteration"></span></div> <video width="320" height="240" id="myVideo" controls> <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4" /> <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv" type="video/ogg" /> Your browser does not support the video tag. </video>
iterations
1
myVideo
5
currentTime
0
play()