4#include "AudioSource.h"
5#include "AudioTools/Communication/HTTP/AbstractURLStream.h"
6#include "AudioToolsConfig.h"
18 template <
typename T,
size_t N>
20 const char* mime,
int startPos = 0) {
22 this->actual_stream = &urlStream;
24 this->urlArray = urlArray;
26 this->pos = startPos - 1;
27 this->timeout_auto_next_value = 20000;
40 if (started) actual_stream->end();
46 if (size() == 0)
return nullptr;
50 LOGI(
"url array out of limits: %d -> %d", idx, pos);
54 LOGI(
"url array out of limits: %d -> %d", idx, pos);
56 LOGI(
"selectStream: %d/%d -> %s", pos, size() - 1, value(pos));
57 if (started) actual_stream->end();
58 const char* url = value(pos);
59 if (url ==
nullptr)
return nullptr;
60 actual_stream->begin(url, mime);
68 if (pos < 0 || pos >= size()) {
71 LOGI(
"nextStream: %d/%d -> %s", pos, max - 1, value(pos));
78 if (pos < 0 || pos >= size()) {
81 LOGI(
"previousStream: %d/%d -> %s", pos, size() - 1, value(pos));
87 LOGI(
"selectStream: %s", path);
88 if (started) actual_stream->end();
89 actual_stream->begin(path, mime);
96 const char*
toStr() {
return value(pos); }
99 void setTimeout(
int millisec) { actual_stream->setTimeout(millisec); }
105 bool setMetadataCallback(
void (*fn)(
MetaDataType info,
const char* str,
109 return actual_stream->setMetadataCallback(fn);
112 virtual int size() {
return max; }
115 AbstractURLStream* actual_stream =
nullptr;
116 const char** urlArray =
nullptr;
119 const char* mime =
nullptr;
120 bool started =
false;
125 virtual const char* value(
int pos) {
126 if (urlArray ==
nullptr || size() == 0)
return nullptr;
127 return urlArray[pos];
142 template <
typename T,
size_t N>
144 const char* mime,
int startPos = 0) {
145 this->actual_stream = &urlStream;
147 this->pos = startPos - 1;
148 this->timeout_auto_next_value = 20000;
149 for (
int j = 0; j < N; j++) {
155 const char* mime =
nullptr,
int startPos = 0) {
156 this->actual_stream = &urlStream;
158 this->pos = startPos - 1;
159 this->timeout_auto_next_value = 20000;
163 void addURL(
const char* url) { url_vector.push_back(url); }
165 void clear() { url_vector.clear(); }
167 int size()
override {
return url_vector.size(); }
171 LOGI(
"selectStream: %s", path);
173 if (started) actual_stream->end();
174 actual_stream->begin(path, mime);
176 return actual_stream;
182 const char* value(
int pos)
override {
return url_vector[pos].c_str(); }