// Enumerate and possibly display the animated GIF filenames in GIFS directory int enumerateGIFFiles(const char *directoryName, boolean displayFilenames) { numberOfFiles = 0; // Set the current working directory if (! sd.chdir(directoryName, true)) { sd.errorHalt("Could not change to gifs directory"); } sd.vwd()->rewind(); char fn[13]; while (file.openNext(sd.vwd(), O_READ)) { file.getName(fn, 13); // If filename not deleted, count it if (fn[0] != '_') { numberOfFiles++; if (displayFilenames) { Serial.println(fn); delay(20); } } file.close(); } // Set the current working directory if (! sd.chdir("/", true)) { sd.errorHalt("Could not change to root directory"); } return numberOfFiles; }
// Get the full path/filename of the GIF file with specified index void getGIFFilenameByIndex(const char *directoryName, int index, char *pnBuffer) { char filename[13]; // Make sure index is in range if ((index >= 0) && (index < numberOfFiles)) { // Set the current working directory if (! sd.chdir(directoryName, true)) { sd.errorHalt("Could not change to gifs directory"); } // Make sure file is closed before starting file.close(); // Rewind the directory to the beginning sd.vwd()->rewind(); while ((file.openNext(sd.vwd(), O_READ)) && (index >= 0)) { file.getName(filename, 13); // If filename is not marked as deleted, count it if ((filename[0] != '_') && (filename[0] != '~')) { index--; } file.close(); } // Set the current working directory back to root if (! sd.chdir("/", true)) { sd.errorHalt("Could not change to root directory"); } // Copy the directory name into the pathname buffer strcpy(pnBuffer, directoryName); // Append the filename to the pathname strcat(pnBuffer, filename); } }
void MP3Player::PlayTrack(const char* dirName,int track_no,const char* track_name) { if(!PLAY) { finishSearch = false; int count=0; //if(track_no>0) //counter = track_no; if(!isPlayAll) { char temp[20]; isPlayAll = true; sd.chdir();delayMicroseconds(100000); sd.chdir(dirName,true); sd.vwd()->rewind(); sd.vwd()->getName(temp,20); currentDir = temp; counter = 0; } while(true) { if(myFile.openNext(myFile.cwd(), O_READ)) { char FileName[80]; myFile.getName(FileName,80); #if DEBUG //myFile.printName(&Serial); Serial.print(FileName); if (myFile.isDir()) { // Indicate a directory. Serial.write('/'); } Serial.println(); #endif if (!(myFile.isDir()||(String(FileName).indexOf(".mp3")==-1&&String(FileName).indexOf(".MP3")==-1))) { counter++; if(ls_flag) { Serial.print(counter); Serial.print(". "); Serial.print(FileName); Serial.print(" "); Serial.print(myFile.fileSize()); Serial.println(" bytes"); myFile.close(); continue; } //Play(FileName); if(!String(track_name).equals("")) { //counter++; if(String(track_name).equals(FileName)) { Play(FileName); //name = track_name; isPlayAll = false; break; } } else if(track_no==0) { //counter++; Play(FileName); break; } else if(track_no>0) { count++; if(count==track_no) { counter = track_no; Play(FileName); isPlayAll = false; break; } } } } else { isPlayAll = false; finishSearch = true; ls_flag = false; break; } //myFile.getFilename(FileName); myFile.close(); } } }