Trying to make a website where a random webm is loaded when the page is entered and/or the video is clicked on but nothing seems to be loading. Here’s the javascript I was given;
[CODE]window.onload = function () {
// A list of your video URLs in a folder called vid
var myVideoList = [];
// Function to load a new video
var loadNewVideo = function () {
// Randomly select a video URL from myVideoList
var selectedVideo = myVideoList[Math.floor(Math.random() * myVideoList.length – 1) + 1];
// Set the source tag of the video and start it playing
var myVideo = document.getElementById(“my-video”);
var myVideoSource = document.getElementById(“my-video-source”);
myVideoSource.src = selectedVideo;
myVideo.load();
myVideo.play();
}
// Get list of *.webm files from folder
$.ajax({
method: “GET”,
url: “/vid”,
success: function(data) {
var files = data.match(/title=”(.*)”/g);
// add video paths to myVideoList
for (var i = 0; i < files.length; i++) {
if (files[i].indexOf(“.webm”) > -1) {
var temp = files[i].split(‘title=”‘);
temp = temp[1].replace(“””, “”);
myVideoList.push(“/vid/” + temp);
}
}
// load first video
loadNewVideo();
// Video click event
$(“#my-video”).click(function () {
loadNewVideo();
});
},
error: function () {
alert(“Error loading files”);
}
});
}
Any ideas? My browser console says the line [B]for (var i = 0; i < files.length; i++) {
Thanks