MCPcopy Create free account
hub / github.com/BruceDevices/firmware / validateAudioFile

Function validateAudioFile

src/modules/others/audio.cpp:139–172  ·  view source on GitHub ↗

Helper to validate file existence

Source from the content-addressed store, hash-verified

137
138// Helper to validate file existence
139static bool validateAudioFile(FS *fs, const String &filepath) {
140 if (!fs) {
141 Serial.println("ERROR: Invalid filesystem pointer");
142 return false;
143 }
144
145 if (!fs->exists(filepath.c_str())) {
146 Serial.print("ERROR: Audio file not found: ");
147 Serial.println(filepath);
148 return false;
149 }
150
151 File file = fs->open(filepath.c_str(), "r");
152 if (!file) {
153 Serial.println("ERROR: Cannot open audio file");
154 return false;
155 }
156
157 bool isFile = !file.isDirectory();
158 size_t fileSize = file.size();
159 file.close();
160
161 if (!isFile) {
162 Serial.println("ERROR: Path is a directory, not a file");
163 return false;
164 }
165
166 if (fileSize == 0) {
167 Serial.println("ERROR: Audio file is empty");
168 return false;
169 }
170
171 return true;
172}
173
174// ===== ASYNC PLAYBACK TASK =====
175static void audioPlaybackTask(void *parameter) {

Callers 1

playAudioFileFunction · 0.85

Calls 4

sizeMethod · 0.80
closeMethod · 0.80
printlnMethod · 0.45
printMethod · 0.45

Tested by

no test coverage detected