0

I have an MP3 shield on a Arduino Uno. When using "File Player" I can get the tracks to play by keyboard entry with three digits (001-009).

The problem is that I want to use (SFEMP3Shield > examples > MP3ButtonPlayer2) that is looking for files 1-9. Any file numbers other than 1,2,3,4,5,6,7,8,9 doesn’t work. Any suggestions?

1

1 Answer 1

1

The playTrack function used in MP3ButtonPlayer2 example plays file with name created with printf format "track%03d.mp3". %03d creates a number prefixed with zeros to lenght 3. For example track005.mp3 or track042.mp3 or track999.mp3.

implementation of the playTrack function:

uint8_t SFEMP3Shield::playTrack(uint8_t trackNo){

  //a storage place for track names
  char trackName[] = "track001.mp3";
  uint8_t trackNumber = 1;

  //tack the number onto the rest of the filename
  sprintf(trackName, "track%03d.mp3", trackNo);

  //play the file
  return playMP3(trackName);
}

change it to:

uint8_t SFEMP3Shield::playTrack(uint8_t trackNo){

  //a storage place for track names
  char trackName[13];
  int trackNumber = trackNo;

  //tack the number onto the rest of the filename
  sprintf(trackName, "track%03d.mp3", trackNumber);

  //play the file
  return playMP3(trackName);
}
67
  • Thank you, makes sense, but I'm not a programmer, I don't know how to edit the SFEMP3Shield > examples > MP3ButtonPlayer2 to make it work. Commented Oct 22, 2018 at 17:59
  • 1
    put the SD card in a computer and rename the files. You should buy an MP3 player, not an Arduino, if you don't want to code
    – Juraj
    Commented Oct 22, 2018 at 18:10
  • It's part of a larger program that uses code that I have worked out. This is the only thing I haven't been able to work, although Sparkfun says it should out of the box. It just need to play 3 tracks when things happen. I have renamed the tracks may times. Does the code you gave go on the SD card or into the MP3ButtonPlayer2 code? Commented Oct 22, 2018 at 20:02
  • it doesn't go anywhere. it is in the library. (and it's a shame for the author of the library, because it should not be coded as it is)
    – Juraj
    Commented Oct 22, 2018 at 20:06
  • The SFEMP3Shield library is included in the sketch. What am I supposed to rename the tracks to? When I run File Player I get; Commented Oct 22, 2018 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.