Failed to convert array Test1.WAV to "Test1.WAV" to playable in Teensy Wav player object !!

charnjit

Well-known member
i have some mixed types of files on SD card ( .wav .mid .jpeg .txt)
i wrote code to store audio files names to array. i don't know how many file are in sd root . i took
C++:
#define MAX_FILES  256
String filenames[MAX_FILES];
i guess these are not more than 256.
then i function in void setup
C++:
   for (int i = 0; i < MAX_FILES; i++)    {     READ_SD_FILE_NAME ();   }
the function
C++:
  READ_SD_FILE_NAME ();
have
Code:
            void READ_SD_FILE_NAME ()  { 
                 { File root = SD.open("/"); // Open the root directory
  if (root) {
    while (true)  {
      File entry = root.openNextFile();
      if (!entry) {
        // No more files
        break;
      }
      if (!entry.isDirectory()) {     // Only store actual files, not directories
        if (fileCount < MAX_FILES) { // Ensure you don't exceed array bounds
            String filename = entry.name();
          if (filename.endsWith(".WAV") || filename.endsWith(".wav")) 
       {    filenames[fileCount] = filename;
          filenames[fileCount].toUpperCase(); // Convert to uppercase for case-insensitive comparison
          fileCount++;   }
        }
      }
      entry.close();
      }
    root.close();
  }           
  else {
    Serial.println("Error opening root directory From SD Card");
  }
  }   
            }
now
C++:
  filenames[fileCount]
is became Test1.WAV . i can see it in Serial Monitor
C++:
   Serial.println(filenames[fileCount]);
but it cannot be used in
Code:
 playSdWav1.playWav(filenames[fileCount]);
getting error
Code:
no matching function for call to 'AudioPlaySdResmp::playWav(String&)'
as
Code:
 playSdWav1.playWav();
function use
Code:
"Test1.WAV"
file name with inverted comas instead of
Code:
Test1.WAV
please reply ... How to convert
Code:
 filenames[fileCount]
into useable audio file name . how to use it in
Code:
 playSdWav1.playWav(filenames[fileCount]);
????????????????????
Thank you
 
Post the entire code. We can't see what object playSdWav1 is or what the function definition of the playWav() function is.
 
I suspect it's because OP is trying to pass a String to a function expecting char* but the crystal ball is foggy.
 
This seems likely! From the error it looks like we’re calling the teensy-variable-playback library, and `playWav` takes a `const char*` filename. So I’d try this for a start (convert the `String` to a C-style char array):

C++:
playSdWav1.playWav(filenames[fileCount].c_str())
 
thank you all of you to reply .
thank you "ihatemorings'' your code start working
playSdWav1.playWav(filenames[fileCount].c_str())
i modify my code for reading file names to array
C++:
void printFiles(File dir) {
  while (true) {
    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    Serial.print(entry.name());   
                                  //start my code
             String filename = entry.name();
              filename.toUpperCase();   
        if (filename.endsWith(".WAV"))  {
       filenames[fileCount] = filename;   
           fileCount++;     
  }             //end my code
    if (entry.isDirectory()) {
      Serial.println("/");
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}
then i call it in
C++:
playSdWav1.playWav(filenames[fileCount].c_str());
yes it is working ...
again thanks to all seniors....
 
Back
Top