I need help getting files from a folder on the server and using their path as the source for my video tag

45 Views Asked by At

Basically what I've got planned here is this:

let vid1 = "/videos/introduction.mp4";
let vid2 = "/videos/explanation.mp4";
let vid3 = "/videos/conclusion.mp4";

// Next video function

let video_count = 1;

if (nextBtn.addEventListener) {
  nextBtn.addEventListener("click", nextVideo, false);
} else {
  nextBtn.attachEvent("onclick", nextVideo);
}

function nextVideo() {
  video_count++;
  if (video_count == 16) video_count = 1;
  let nextVid  = "vid" + video_count;
  video.src = nextVid;
}

// Previous video function

previousBtn.addEventListener("click", prevVideo);
function prevVideo() {
  video_count--;
  if (video_count == 0) video_count = 1;
  // THIS LINE is the problem
  let prevVid = "vid" + video_count;
  video.src = prevVid;
}

In both let = nextVid and let = prevVid I want it so that the video source is set to the vid2 variable, but it displays it as .../videos/vid2. I want it to be .../videos/explanation.mp4. Removing the quotation marks makes vid undefined, but if I try to define it I won't know what to code from there as I'm not familiar with arrays.

My current code has been modified from here.

I also tried using Node.js but I don't know how to display the directory listing onto the server. I'm just starting out JS and I understand it pretty well and still learning so corrections and criticism are greatly appreciated.

0

There are 0 best solutions below