What I want to achieve is for the video source to be set randomly from "1.mp4" to "4.mp4", where the rand. int is generated on every load/refresh.
Javascript:
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}
var video = document.getElementById("video");
video.setAttribute('src', getRndInteger(1,4) + '.mp4');
video.load();
HTML:
<video autoplay muted loop id="video"></video>
Unfortunately, no video plays when loading the website. I tried changing the src of a source as well, but it doesn't work using this method. I also tried adding video.play(); which doesn't work as well. Any help is appreciated!
Aucun commentaire:
Enregistrer un commentaire