jPlayer - Play random audio files based on files in folder

279 Views Asked by At

Hy, I'am using the jPlayer ( from this Site https://jplayer.org/ ) to play audio files based on playlists. Now i would like to play random audio files from a folder. There are a lot of instructions about that on stackoverflow but the most of them are based on loading the whole folder content into a playlist and play it randomly. I'am not sure if it's a good approach in my case because i have a huge folder with audio files. So is it possible to play audio files randomly without adding them to a playlist ?

1

There are 1 best solutions below

2
Aaron Machin On

I'd personally recommend finding all the files you want to play and storing the file path to each individual file in an array, and playing them in whatever sequence you desire. This is an argument of disk-storage over memory-storage, and memory storage is quicker. I doubt you'll run out of space by just reading and saving the file-paths.

However, if your folder really is that large - or maybe you just want the performance, I'd recommend splitting up those files into sub-directories. You can then set up your code to load each sub-directory individually. However, you may lose some of the 'randomness' as they are not in the same folder.

In addition to the storing all the filepaths, you may also want to start loading the next audio file before the one you're currently playing ends so that you don't have any stops or 'lag'.