Store SD file names as an array

Hello Peps

I am currently working on my own mp3 player and I ran into a problem. All the mp3 files are saved on a SD-card, which is connected to the arduino.

It is possible for me to print all the names out: printDirectory(SD.open("/"), 0);
But how can I save them in an Array? I will use the array to shuffle through the songs, when a command for changing track has been chosen.

Thanks.

Can you play songs by number? Or make the file names S0001.mp3, S0002.mp3, etc?

You don't have RAM to hold many song names.

You could make a file with 1 name per line and another file of offsets into that file, 1 per name line.
Every number in the second file (the link file) has the location in the first of the matching name.

This is to keep from needing to read name after name to get to the chosen random name.

Suppose the file of names is length 32K or less. Then the link file will have 2 bytes (int) per link. If I want to find song 10 starting from 1, I read the 10th value then look in the name file at that position and the song name should be there.

That would be one way to work it with all the data kept on the same SD card as the mp3 files.

Thanks a lot! Did not even think about that solution! I will try that out.

I can play songs by their name on the SD-card :slight_smile:

qvisten999:
Thanks a lot! Did not even think about that solution! I will try that out.

I can play songs by their name on the SD-card :slight_smile:

You understand the use of offsets into data then? Good!

Will you generate the name file and link file(s) on PC or Arduino?
You can have a link file for every use you want, like to access songs as an album start with song count and make one link (offset) per song in song order then your sketch can use that to get the file names and play.

Best part about SD, gigabytes! To compare: my first HD's were 5 megabyte space and to me that was a lot.