playlist with mp3 shield

Hi,
I'm french ... so excuse for my broken english...
I'm trying to make a playlist with my uno and mp3 sparkfun shield...
So i'ved mount the librery (SFMP3Shield and FAT32) and runed the examples, and everythings all right.

Now I trie to code by my self to make a playlist of 3 mp3 (please indulgence :sweat_smile:)

#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h> 
#include <SFEMP3Shield.h>

SdFat sd;
SFEMP3Shield MP3player;

void setup() {

  Serial.begin(115200);

  //start the shield
  sd.begin(SD_SEL, SPI_HALF_SPEED);
  MP3player.begin();


}

//playlist
void loop() {
  delay(100);
  MP3player.playTrack(25);
  if (MP3player.isPlaying()==0){
    MP3player.stopTrack();
  }
  delay(100);
  MP3player.playTrack(28);
  if (MP3player.isPlaying()==0){
    MP3player.stopTrack();
  }
  delay(100);
  MP3player.playTrack(32);
  if (MP3player.isPlaying()==0){
    MP3player.stopTrack();
  }
}

It work but not exactely as I like... traks does'nt run in the right order ...
Would you help me please :sweat_smile:
Tell me if you need more information.

Hello

I know you posted this long time ago, however i had the same problem but finally i managed to solve it.. so i want to post in here in case someone else needs it.

So, i saw your code and i noticed that the shield doesnt play the songs in order, because it dont wait till the song has finished playing in order to play the next song.

What is happening in your code is that it asks the shield if the song has finished playing every 100 ms, however the song could have finished playing 10ms, 20ms or even 90ms before the command seeks again and at that moment the arduino tells to the shield to play the song that at that moment is going through the code.

So to solve this you can use the next code:

int IsAnySongPlaying;
int SongNumber;

IsAnySongPlaying= MP3player.isPlaying();

if (IsAnySongPlaying==0)
{
SongNumber++;
MP3player.playTrack(SongNumber);
}