I'm trying to create a function in my arduino sketch that will return the number of MP3 files that I've loaded onto the SD card of the yun, in the '/mnt/sda1/MP3' folder.
This is the code I have so far:
#include <Bridge.h>
#include <FileIO.h>
int _max = 0;
void setup() {
Serial.begin(9600);
FileSystem.begin();
Bridge.begin();
countMP3s();
Serial.println(_max);
}
void countMP3s() {
_max = 0;
File mp3s = FileSystem.open("/mnt/sda1/MP3");
mp3s.rewindDirectory();
while (true) {
File f = mp3s.openNextFile();
if (f) {
if (String(f.name()).endsWith(".mp3") ) {
_max++;
}
f.close();
} else {
break;
}
}
mp3s.close();
}
The problem I'm running into is that my countMP3s() function only ever returns a value of '1' - even though there are multiple .mp3 files within the /mnt/sda1/MP3 folder. It looks like for some reason its breaking out of the while loop early, but I can't figure out why.
Can anyone help on this?
Another side question: Is it necessary to include the 'FileSystem.begin();' line for this? Is this required whenever using the File class in the arduino sketch? Just want to confirm
Thanks for any help!