Indexing and random playing mp3 files

I'm surprised that I couldn't find an example of this being done as a lot of people talk about it but no code is posted.

I am playing with the Adafruit mp3 breakout and would like the Arduino to read the names of the files, index them, and play them randomly. I would like to keep the names descriptive (as much as you can do with 8 characters). Also, I would like to be able to update the sd and have the arduino automatically include the new files.

I want to avoid writing the names to an array as that would consume too much memory.

I thought of writing the names to a temp .txt file that the arduino prepares each time it starts. Then I could generate a random number that corresponds to a line in the .txt file, then read the line into a char and play the file.

I would imagine that I would use openNextFile(), but I don't know how to read the file names from that call. Also, I haven't found how to turn a line in a txt file into a char.

Then there is the possibility that I am approaching this entirely wrong, so any input would be appreciated.

I'd suggest writing two functions for your program: - int countMP3files() - char* getMP3fileName(int index)

The countMP3files() function would then be called just once from the setup() and the number of files stored in a variable (i.e. 'int totalSongs=countMP3files();').

Then you could at any time create a random number and retrieve the name of that file.

  int songNumber= random(totalSongs);
  char* songName=getMP3fileName(songNumber);

Advantage: Saves RAM, saves complicated programming Disadvantage: If there are many files, retrieving the file name will cost time for searching the file name.

How would I get the file name by index?

Read by line in a text file? Or use openNextFile() index number of times?

pekasus: How would I get the file name by index?

Read by line in a text file? Or use openNextFile() index number of times?

Use openNextFile() index number of times and then get the name.