Helper to validate file existence
| 137 | |
| 138 | // Helper to validate file existence |
| 139 | static 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 ===== |
| 175 | static void audioPlaybackTask(void *parameter) { |
no test coverage detected