3

I am trying to build an HTML5 video player that will automatically turn on playlist mode if there is more than one video file in the /videos folder.

I'm trying not to use PHP for this so please keep that in mind when suggesting something.

Thank you.

2
  • 2
    There is no way to "list" remote files in JavaScript, except as exposed by the server. In this case the best method would be to ask the server to provide the information somehow. Commented Sep 10, 2015 at 19:12
  • Anyway. this could also be done via convention, ie. video1.mpg, video2.mpg, videoN.mpg .. in which case the resource names are guessed - well, just checked in sequence - until one fails to load. Not that I recommend it, but it does avoid the need to "list" resources. Commented Sep 10, 2015 at 19:14

1 Answer 1

3

You cannot access file-system using JavaScript. But, you can do a fake HTTP request to the directory with index access:

var dir = "/videos";
var fileextension = ".mp4";
$.ajax({
    //This will retrieve the contents of the folder if the folder is configured as 'browsable'
    url: dir,
    success: function (data) {
        // List all mp4 file names in the page
        $(data).find("a:contains(" + fileextension + ")").each(function () {
            var filename = this.href.replace(window.location.host, "").replace("http:///", "");
            $("body").append($("<img src=" + dir + filename + "></img>"));
        });
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.