2 #include "AudioTools/CoreAudio/AudioBasic/Str.h"
28 LOGE(
"Not Supported!");
42 timeout_auto_next_value = millisec;
47 return timeout_auto_next_value;
68 int timeout_auto_next_value = 500;
84 this->onStartCallback = onStartCallback;
85 this->nextStreamCallback = nextStreamCallback;
91 if (onStartCallback !=
nullptr) onStartCallback();
97 return nextStreamCallback ==
nullptr ? nullptr : nextStreamCallback(offset);
102 LOGI(
"selectStream: %d", index);
103 if (indexStreamCallback==
nullptr){
104 LOGI(
"setCallbackSelectStream not provided");
113 return indexStreamCallback(index);
118 return indexStreamCallback ==
nullptr ? nullptr : indexStreamCallback(-1);
121 void setCallbackOnStart(
void (*callback)()) {
122 onStartCallback = callback;
125 void setCallbackNextStream(Stream* (*callback)(
int offset)) {
126 nextStreamCallback = callback;
129 void setCallbackSelectStream(Stream* (*callback)(
int idx)) {
130 indexStreamCallback = callback;
137 virtual void setAutoNext(
bool a){
142 virtual const char* getPath() {
147 void (*onStartCallback)() =
nullptr;
148 bool auto_next =
true;
149 Stream* (*nextStreamCallback)(
int offset) =
nullptr;
150 Stream* (*indexStreamCallback)(
int index) =
nullptr;
151 const char*path=
nullptr;
154 #if defined(USE_URL_ARDUINO) && ( defined(ESP32) || defined(ESP8266) )
164 template<
typename T,
size_t N>
167 this->actual_stream = &urlStream;
169 this->urlArray = urlArray;
171 this->pos = startPos - 1;
172 this->timeout_auto_next_value = 20000;
186 LOGI(
"url array out of limits: %d -> %d", idx, pos);
190 LOGI(
"url array out of limits: %d -> %d", idx, pos);
192 LOGI(
"selectStream: %d/%d -> %s", pos, size() - 1, value(pos));
193 if (started) actual_stream->end();
194 actual_stream->begin(value(pos), mime);
196 return actual_stream;
202 if (pos < 0 || pos >= size()) {
205 LOGI(
"nextStream: %d/%d -> %s", pos, max-1, value(pos));
212 if (pos < 0 || pos >= size()) {
215 LOGI(
"previousStream: %d/%d -> %s", pos, size() - 1, value(pos));
221 LOGI(
"selectStream: %s", path);
222 if (started) actual_stream->end();
223 actual_stream->begin(path, mime);
225 return actual_stream;
232 const char *toStr() {
238 actual_stream->setTimeout(millisec);
249 return actual_stream->setMetadataCallback(fn);
254 AbstractURLStream* actual_stream =
nullptr;
255 const char** urlArray =
nullptr;
258 const char* mime =
nullptr;
259 bool started =
false;
264 virtual const char* value(
int pos){
265 if (urlArray==
nullptr)
return nullptr;
266 return urlArray[pos];
285 template<
typename T,
size_t N>
287 this->actual_stream = &urlStream;
289 this->pos = startPos - 1;
290 this->timeout_auto_next_value = 20000;
291 for (
int j=0;j<N;j++){
297 this->actual_stream = &urlStream;
299 this->pos = startPos - 1;
300 this->timeout_auto_next_value = 20000;
305 url_vector.push_back(url);
313 Vector<Str> url_vector;
315 const char* value(
int pos)
override {
316 return url_vector[pos].c_str();
319 int size()
override {
320 return url_vector.size();