I've implemented an HTML5 video as a full screen background video. Each time someone opens the page or refreshes it, I'd like to have the background video randomly change to another one (I'll have about 3 or 4 videos that could be chosen.) Until the page is refreshed or reopened just that one video would play, though. It wouldn't loop through the 3 or 4 videos if that makes sense.
This question was flagged as a duplicate for another, which gave me part of the answer.
var videoList = ["video1", "video2", "video3", "video4", "video5"];
videoList.sort(function (a, b) {
return Math.random() > 0.5 ? -1 : 1;
My question now is, how do I 'tie' these video files to the source of the html video?
<video autoplay poster="" id="bgvid" loop>
<source src="?" type="video/webm">
<source src="?" type="video/mp4">
</video>