Need Help Random File MP3 Player . Thank you

I could use some help - Need a random MP3 file to play 1/10 short bursts of sound files every 1 second generating a random number in an while loop ??
I'm using a MP3 Uno Sheild .
I have x10 MP3s on a SD . 1.mp3, 2.mp3, 4 .mp3 .
I'm using the code* below, and it's only playing the single 1.mp3
*@Grumpy_Mike wrote the original code (thankyou)

long indexToWrite;
char toPlay[11];     //  

// function makeName 
void makeName(int number, int depth){  // generates a file name 0.mp3 to 9999.mp3 suppressing leading zeros
  if(number > 9) {
    makeName(number / 10, ++depth); // recursion
    depth--;
    number = number % 10;   // only have to deal with the next significant digit of the number
     }
  toPlay[indexToWrite] = (number & 0xf) | 0x30;
  indexToWrite++;
  if(depth > 0) return; // return if we have more levels of recursion to go
  else {  // finish off the string with the wave extesion
     toPlay[indexToWrite] = '.';
     toPlay[1+indexToWrite] = 'm';
     toPlay[2+indexToWrite] = 'p';
     toPlay[3+indexToWrite] = '3';
     toPlay[4+indexToWrite] = '\0'; // terminator
     indexToWrite = 0; // reset pointer for next time we enter
  }
}

void loop() {
  makeName(randNumber,0);  // generate file name in global array 
  musicPlayer.startPlayingFile(toPlay);
}

Ok.
That code does not pause for a second anywhere.
Try putting a delay of a second after you set the MP3 file playing.

Make sure also that one of your files is called 0.MP3.

Now you do not have anything that will generate a random number. You just pass the number zero each time you call the makeName function.

See this page for how to generate random numbers.
Random numbers

Since an MP3 file takes some decoding try using a .wav file, they will start faster if you are using this file type.

Also make sure your sounds start as quick as possible by trimming the silence at the start of the sound.

Thank you @Grumpy_Mike

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.