examples not using next #1509
-
Most of the examples seem to be from a players point of view using next/previous to select an SD card file . I am using my ESP32 as a source with an SD card and MP3 files I want to play on a BT speaker. Does anyone have an example of choosing a filename to play, then calling a 'play music file' routine that returns after the file has played. |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 2 replies
-
I suggest that you have a look at the Audio Player wiki! |
Beta Was this translation helpful? Give feedback.
-
Thanks for a quick reply. I don't think I'm trying to do anything too fancy. Sd card files are all mp3s. I test for all files on the inserted card. Enable Wifi to sync time, then disable. Setup finishes with connecting to a BT speaker. In loop I watch for new seconds and call check for events if its a new minute. the remainder of the loop watches player.copy() to determine if the any file is playing. void loop()
} void playMusic()
} The files play a few times and then they either are garbled (stuttered) or every thing freezes altogether. |
Beta Was this translation helpful? Give feedback.
-
The project steams mp3 files of the Westminster chime including hours gongs every hour and Westminster quarters on the quarter hour. SD card contains 24 hour mp3 files and 3 quarter hour mp3 files. |
Beta Was this translation helpful? Give feedback.
-
The checkForEvents function assigns the appropriate file at the appropriate time to myMusic and calls playMusic. |
Beta Was this translation helpful? Give feedback.
-
If I understand you correctly, the player is not the right tool to use for this. I should be using using the stream function. Looking at your suggestion I would bsically have to change the I2SStream to A2DPStream. |
Beta Was this translation helpful? Give feedback.
-
I would test this first with another output class: e.g AnalogAudioStream or CSVStream. and do this only at the last step. I expect that the playAll() will not work with A2DP, so you might need to design for using the copier.copy() in the loop like in the example. |
Beta Was this translation helpful? Give feedback.
-
I didn't make much headway by moving to the Stream class. The app makes connection with a BT speaker and waits for the quarterhour to play an Westminster chime (MP3). The connection remains open while waiting for the next quarter hour and it plays again. This goes on for a number of quarter hours and then the audio degrades. Eventually it fails to play anymore and locks up. I got this message one time... |
Beta Was this translation helpful? Give feedback.
-
You obviously still have some bug in your code! |
Beta Was this translation helpful? Give feedback.
-
Please excuse my ignorance. None of the examples show closing any file. |
Beta Was this translation helpful? Give feedback.
I suggest that you have a look at the Audio Player wiki!
You could provide your own AudioSource or use the AudioSourceCallback: this way you can basically implement any logic you want.