Closed dagnall53 closed 4 years ago
I am now using this code in my esp8266 in case anyone want to copy or improve..BUT it odes not work with ESP32 ! ` bool FileExists(const char *wavfilename){ File TestObj; if (!(TestObj= SPIFFS.open(wavfilename,"r"))){
DebugSprintfMsgSend( sprintf ( DebugMsg, " SFX File not found %s",wavfilename)); // sends me a debug message
#endif
malloc(TestObj);
return false;
}
malloc(TestObj); return true; }`
Opened again as The code above only works for ESP8266 NOT esp32.. (although my esp32 does seem to be stable even if I open a non existent file..!)
if (AudioFileSourceSPIFFS.open(wavfilename)){
file[Channel]= new AudioFileSourceSPIFFS(wavfilename);}
else {DebugSprintfMsgSend( sprintf ( DebugMsg,"SFX No such file name")); }
But I get "expected primary-expression before '.' token"
You've got a C++ syntax problem. You need to make an object of the class, then use that variable to call open and check the return value:
AudioFileSourceSPIFFS f;
if (!f.open(wavfile)) ....
Earle, I am sure this is trivial, but I am trying to put in checks that a File actually exists before allowing my sound code to run. I tried something like this
But I get
"expected primary-expression before '.' token"
Is there an easy way to use the file open Boolean that seems to be in your AudioFileSourceSpiffs.cpp
(bool AudioFileSourceSPIFFS::open(const char *filename)
?Reason for doing this is that the code seems to accept non present SPIFFS filenames, but then does not detect end of file, so "plays" non stop.. (thus stopping me starting a new file sound play). I'm trying to update my Rocrail sound stuff to ESP32 and wanted to put in some checks to make it more bulletproof.. Huge thanks Dagnall