Home Forums Sparkfun MP3 Shield Library Support Forum Triggering mp3 file over serial Reply To: Triggering mp3 file over serial

#2388

The code is an example, meant to demonstrate features and was purposed to be as flexible as possible. Where my implementation wanted to be able to play and infinite list other files, beyond that of track0000.mp3. Hence the play and list feature simply sequence through the openNext of the SdCard, displaying all playable files with matching *.ext.

fileplayer.ino Line 372:

while (file.openNext(sd.vwd(),O_READ))
{
file.getFilename(filename);
if ( isFnMusic(filename) ) {
SerialPrintPaddedNumber(count, 5 );
Serial.print(F(“: “));
Serial.println(filename);
count++;
}
file.close();
}

I would expect the list and its corresponding enumerations should be consistent, as the openNext(), is sequencing through the SdCard’s FAT entries. Which should not change, unless you add files to it. Which won’t be something you do often, or on the fly at least. So I suspect you can manually list out the playable files with the “l” command and go with that list, until you change things. At which time you could check it again.

That all said. There is nothing preventing you from changing the code (it is an example) to fit your own needs. where you can change the below section to your needs.

fileplayer.ino Line 173:

while (file.openNext(sd.vwd(),O_READ))
{
file.getFilename(filename);
if ( isFnMusic(filename) ) {

if (count == fn_index) {
Serial.print(F(“Index “));
SerialPrintPaddedNumber(count, 5 );
Serial.print(F(“: “));
Serial.println(filename);
Serial.print(F(“Playing filename: “));
Serial.println(filename);
int8_t result = MP3player.playMP3(filename);

I recall your original problem is that you wanted to play a specific track, but not limited to 0-9 tracks. and were having problems with multi digit characters being sent and received. You can remove the above while (file.openNex… file.GetFilename and if( isFnMusic… and replace filename with a construction of your choice, similar to what happens at lines.

The fileplayer.ino can help that. Where it was developed for a more general application. The features of ICT or delimiting can be re-used, by stream lining/hacking to better fit your needs.

Ahh, screw it. I just made it and posted it here on GISTHUB  trackplayer-ino

This should do what you want. Simply send in 1, 01, 001, 0001 or o0001 to play TRACK001.MP3. Same for 02 to play TRACK002.MP3 and so on. Where you need to make sure your sender has at least 500ms pause between numbers or commands.

Diff TrackPlayer.ino and FilePlayer.ino to see the differences as mentioned above.

If you don’t want the 500ms then, you can change the code to remove the ICT and use something like CR/LF as the delimit to queue parsing.