I'm building my first arduino project that plays some random mp3s. I'm a PHP programmer, so I understand the basics, but will be learning C++ as I go (be gentle! ) I'll be using the Sparkfun MP3 shield, which uses the SFEMP3Shield and SDFat libraries.
The main thing I can't figure out right now is how to choose files in this scenario:
Lets say I have 10 files on the SD card. I want to randomly grab a track (by file NAME, not number) and play it. Then randomly grab another and play it, etc. BUT I want to make sure none of them repeat until all 10 have been played.
I was thinking I'd get a list of all files on the SD card (again, because I need their names, not a track number), put them in an array, grab a random one, then remove the played file from the array. Then when the array is empty, repopulate it again and start over.
Is this a good approach or would you do it a different way (again, I'm a noob, please keep it as simple as possible). Is it possible to do all this with the SDFat library? Should I also/instead use the SD library?
Any direction to get started on this is much appreciated. Thanks!
Thanks, so that implies you're thinking I should use the SD library instead of SDFat. I was starting to think that too (seems simpler, maybe). Googling now...
K, thanks. I was thinking that 'shuffle' may replay the same file before all have been played, but I'll look into what kind of shuffle may be available for the mp3 player library.
Shuffle, to satisfy the non-repetition requirement. Nothing to do with the "shuffle" of a consumer player...
Marking them as used works too, as mentioned above. Maybe easier for you...
My thought about a shuffled list of indices, is that the play logic is simplified, one pass through all the files using the pre-shuffled indices. No need to keep track of which have been played.
Great thoughts here. I like using the index number instead of file names! EDIT: The "marking it as played" may be a challenge that my noob skills can't figure at this point, maybe.
I also like the idea of preshuffling the array, then just playing through it. May be simpler since I know almost zero C++ at this point. That would just entail:
Got it...so I'd need to know many items in the array so I would need have the correct amount of array keys to shuffle, then call the array items in that (randomized) order by key.
This is sounding a little more complicated than I hoped
EDIT: Number of items will be variable...thats why I need to retrieve the file list as an array as part of the sketch.
yeah, note sure how many, but almost certainly more than 10. Some good ideas here, thanks for the assistance! I'll dig into those libraries now and see what functions they have to get files in a directory to create an array (haven't' found much yet).
I thought I could programmatically get a list of all the file names, put them in an array, then randomly choose one...but it looks like that's too simplistic.
I like the idea of random index numbers (which are then used to get a filename). Seems much simpler, thanks!