Skip to content

Commit

Permalink
Update random_video.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lraithel15133 authored Feb 7, 2024
1 parent f6e5d41 commit ad591b5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions videos/random_video.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@ window.addEventListener("DOMContentLoaded", function () {
function createSource(video, mimetype) {
var source = document.createElement("source");
source.src = video;
source.mimetype = mimetype;
source.type = mimetype;
return source;
}

function randomVideo() {
var video = videos[Math.floor(Math.random() * videos.length)];

videoTag.src = "videos/" + video + ".webm";

videoTag.innerHTML = '';


var webmSource = createSource(`videos/${video}.webm`, 'video/webm');
var mp4Source = createSource(`videos/${video}.mp4`, 'video/mp4');


videoTag.appendChild(webmSource);
videoTag.appendChild(mp4Source);

videoTag.load(); // Important to reload the video tag to apply new sources
}
videoTag.addEventListener("ended", randomVideo);
randomVideo();
Expand Down

0 comments on commit ad591b5

Please sign in to comment.