Commit ddc5029
authored
add playFile() blocking method for audio playback (#2048)
summary:
adds a new `playFile(const char *filePath)` method to the `AudioPlayer` class that provides a simple blocking way to play a complete audio file from start to finish.
- new method: `bool playFile(const char *filePath)` in the public section of `AudioPlayer` class
- functionality:
- sets the audio file path using existing `setPath()` method
- starts playback with `play()`
- blocks execution until the entire file finishes playing
- automatically stops when no more audio data is available
- returns `true` on success, `false` if file cannot be opened
use case:
i used this library for an ESP32 project at school and needed a blocking method to do nothing BUT play a specific audio file before continuing the program, so i made my own and thought other people might need it!
example usage:
```cpp
AudioPlayer player(source, output, decoder);
...
setup() {
player.begin();
}
...
loop() {
// play a complete file (blocking)
if (player.playFile("/song1.mp3")) {
// file plays successfully
} else {
// file not found or other error occurred
}
doSomething();
}
```
this addition shouldn't affect any existing functionality!1 parent 1637404 commit ddc5029
1 file changed
+26
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
255 | 281 | | |
256 | 282 | | |
257 | 283 | | |
| |||
0 commit comments