1

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 ?

Bennek
  • 25
  • 4
  • [Pass songs to Jplayer dynamically](https://stackoverflow.com/questions/14268947/how-to-dynamically-pass-songs-to-jplayer) should allow you to pass single songs dynamically to JPlayer. – Nathan Champion Sep 10 '20 at 15:26
  • No, i think that's not what i'm searching for. – Bennek Sep 10 '20 at 15:43

1 Answers1

0

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'.

  • Is it really necessary to store all the filepaths ? Isn't it possible to just select them randomly ? – Bennek Sep 10 '20 at 15:45
  • Apologies for the wait; You could attempt to read the amount of files in a directory and then each time you wish to play one, load the nth file in the range of 0 to the amount of files. However, this will mean a disk read of the entire folder each time. Additionally, whilst I do not know your project fully, it may be recommended that you want to provide a less random system. If you are attempting a music player, total randomness isn't random enough, weirdly. Read this: https://www.independent.co.uk/life-style/gadgets-and-tech/news/why-random-shuffle-feels-far-random-10066621.html – Aaron Machin Oct 12 '20 at 16:13