Fetching Dynamic MP3 URLs for AudioSourceURL #1263
-
Hello! First off, what an awesome library. It has been extremely helpful to help me learn (new to c++, esp32 and working with audio). I'm trying to adapt the https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-player/player-url-i2s/ example to be able to fetch an array of urls instead of having them statically defined. The goal is to hit an https endpoint to fetch an array of 2-5 mp3 URLs, play through them, then fetch more, etc... The example works great on my board setup, which is great, I just need to find a way to make the array of urls dynamic. I can easily hit my webserver and retrieve the array of urls, however it seems the AudioSourceURL constructor expects the urls to be defined once globally, and there aren't methods on the class to update or set them after instantiation. Is If there are other examples that would help put me on the right track, or different methods to accomplish this I would be most grateful for any direction anyone can provide. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
You will find the answer in the documentation: An AudioSource is the abstract API used by the AudioPlayer class to navigate and access the audio stream. You can create your own source or just use one of the existing implementations. Just look at the current implementation of AudioSourceURL and replace the c array of char* with a The existing AudioSourceURL tries to be as memory efficient as possible by using the data stored in Progmem where the data can not be changed. This prevents a dynamic solution! |
Beta Was this translation helpful? Give feedback.
-
I have added the new class AudioSourceDynamicURL |
Beta Was this translation helpful? Give feedback.
-
Thank you @pschatzmann!! Your tip about replacing the c array of char* with a Vector helped get me on the right track. I ended up creating a subclass last night that worked perfectly, but didn't reply yet as I was still troubleshooting some performance issues (turned out to be an issue with the bitrate of my mp3 files). Then to have you add that AudioSourceDynamicURL class (which is much more elegant than mine) was a very nice surprise this morning! |
Beta Was this translation helpful? Give feedback.
You will find the answer in the documentation: An AudioSource is the abstract API used by the AudioPlayer class to navigate and access the audio stream. You can create your own source or just use one of the existing implementations.
Just look at the current implementation of AudioSourceURL and replace the c array of char* with a
Vector<String>
orstd::vector<String>
to create your own AudioSourceDynamicURL class.The existing AudioSourceURL tries to be as memory efficient as possible by using the data stored in Progmem where the data can not be changed. This prevents a dynamic solution!