@@ -50,11 +50,18 @@ namespace audio_tools {
50
50
return nullptr ;
51
51
}
52
52
53
+ virtual void setTimeoutMs (int millisec) {
54
+ timeout_value = millisec;
55
+ }
56
+
53
57
// / Provides the timeout which is triggering to move to the next stream
54
58
virtual int timeoutMs () {
55
- return 500 ;
59
+ return timeout_value ;
56
60
}
57
61
62
+ protected:
63
+ int timeout_value = 500 ;
64
+
58
65
};
59
66
60
67
/* *
@@ -74,19 +81,19 @@ namespace audio_tools {
74
81
}
75
82
76
83
// / Reset actual stream and move to root
77
- virtual void begin () {
84
+ virtual void begin () override {
78
85
LOGD (LOG_METHOD);
79
86
if (onStartCallback != nullptr ) onStartCallback ();
80
87
};
81
88
82
89
// / Returns next (with positive index) or previous stream (with negative index)
83
- virtual Stream* nextStream (int offset) {
90
+ virtual Stream* nextStream (int offset) override {
84
91
LOGD (LOG_METHOD);
85
92
return nextStreamCallback == nullptr ? nullptr : nextStreamCallback ();
86
93
}
87
94
88
95
// / Returns selected audio stream
89
- virtual Stream* selectStream (int index) {
96
+ virtual Stream* selectStream (int index) override {
90
97
return indexStreamCallback == nullptr ? nullptr : indexStreamCallback (index);
91
98
}
92
99
@@ -102,7 +109,6 @@ namespace audio_tools {
102
109
indexStreamCallback = callback;
103
110
}
104
111
105
-
106
112
protected:
107
113
void (*onStartCallback)() = nullptr ;
108
114
Stream* (*nextStreamCallback)() = nullptr ;
@@ -139,25 +145,22 @@ namespace audio_tools {
139
145
exension = ext;
140
146
}
141
147
142
- virtual void begin () {
148
+ virtual void begin () override {
143
149
LOGD (LOG_METHOD);
144
- pos = 0 ;
150
+ idx_pos = 0 ;
145
151
}
146
152
147
- virtual Stream* nextStream (int offset) {
148
- LOGD (LOG_METHOD );
149
- return selectStream (pos +offset);
153
+ virtual Stream* nextStream (int offset) override {
154
+ LOGW ( " -> nextStream: %d " , offset );
155
+ return selectStream (idx_pos +offset);
150
156
}
151
157
152
- virtual Stream* selectStream (int index) {
153
- pos = index;
154
- if (pos<0 ){
155
- pos = 0 ;
156
- }
158
+ virtual Stream* selectStream (int index) override {
159
+ idx_pos = index<0 ? 0 : index;
157
160
file.close ();
158
- file = getFile (start_path, pos );
161
+ file = getFile (start_path, idx_pos );
159
162
file.getName (file_name, MAX_FILE_LEN);
160
- LOGI (" -> selectStream: '%s'" , file_name);
163
+ LOGW (" -> selectStream: %d '%s'" , idx_pos , file_name);
161
164
return file ? &file : nullptr ;
162
165
}
163
166
@@ -166,10 +169,20 @@ namespace audio_tools {
166
169
file_name_pattern = filter;
167
170
}
168
171
172
+ // / Provides the current index position
173
+ int index () {
174
+ return idx_pos;
175
+ }
176
+
177
+ // / provides the actual file name
178
+ const char *toStr () {
179
+ return file_name;
180
+ }
181
+
169
182
protected:
170
183
AudioFile file;
171
184
AudioFs sd;
172
- size_t pos = 0 ;
185
+ size_t idx_pos = 0 ;
173
186
char file_name[MAX_FILE_LEN];
174
187
const char * exension = nullptr ;
175
188
const char * start_path = nullptr ;
@@ -258,15 +271,16 @@ namespace audio_tools {
258
271
this ->urlArray = urlArray;
259
272
this ->max = N;
260
273
this ->pos = startPos - 1 ;
274
+ this ->timeout_value = 60000 ;
261
275
}
262
276
263
277
// / Setup Wifi URL
264
- virtual void begin () {
278
+ virtual void begin () override {
265
279
LOGD (LOG_METHOD);
266
280
}
267
281
268
282
// / Opens the next url from the array
269
- Stream* nextStream (int offset) {
283
+ Stream* nextStream (int offset) override {
270
284
pos += offset;
271
285
if (pos < 1 || pos > max) {
272
286
pos = 1 ;
@@ -281,19 +295,19 @@ namespace audio_tools {
281
295
}
282
296
283
297
// / Opens the selected url from the array
284
- Stream* selectStream (int Station) {
298
+ Stream* selectStream (int idx) override {
285
299
// pos += offset;
286
- pos = Station ;
300
+ pos = idx ;
287
301
if (pos < 1 ) {
288
302
pos = 1 ;
289
- LOGI (" url array out of limits: %d -> %d" , Station , pos);
303
+ LOGI (" url array out of limits: %d -> %d" , idx , pos);
290
304
}
291
305
if (pos > max) {
292
306
pos = max;
293
- LOGI (" url array out of limits: %d -> %d" , Station , pos);
307
+ LOGI (" url array out of limits: %d -> %d" , idx , pos);
294
308
}
295
309
LOGI (" selectStream: %d/%d -> %s" , pos, max, urlArray[pos-1 ]);
296
- if (Station != 0 || actual_stream == nullptr ) {
310
+ if (idx != 0 || actual_stream == nullptr ) {
297
311
if (started) actual_stream->end ();
298
312
actual_stream->begin (urlArray[pos-1 ], mime);
299
313
started = true ;
@@ -302,7 +316,7 @@ namespace audio_tools {
302
316
}
303
317
304
318
// / Opens the Previous url from the array
305
- Stream* previousStream (int offset) {
319
+ Stream* previousStream (int offset) override {
306
320
pos -= offset;
307
321
if (pos < 1 || pos > max) {
308
322
pos = max;
@@ -316,12 +330,12 @@ namespace audio_tools {
316
330
return actual_stream;
317
331
}
318
332
319
- void setTimeoutMs ( int millisec ) {
320
- timeout = millisec ;
333
+ int index ( ) {
334
+ return pos ;
321
335
}
322
336
323
- int timeoutMs () {
324
- return timeout ;
337
+ const char * toStr () {
338
+ return urlArray[pos] ;
325
339
}
326
340
327
341
protected:
@@ -330,7 +344,6 @@ namespace audio_tools {
330
344
int pos = 0 ;
331
345
int max = 0 ;
332
346
const char * mime = nullptr ;
333
- int timeout = 60000 ;
334
347
bool started = false ;
335
348
336
349
};
@@ -513,9 +526,9 @@ namespace audio_tools {
513
526
}
514
527
515
528
// / moves to next file
516
- virtual bool next () {
529
+ virtual bool next (int offset= 1 ) {
517
530
LOGD (LOG_METHOD);
518
- active = setStream (*(p_source->nextStream (+ 1 )));
531
+ active = setStream (*(p_source->nextStream (offset )));
519
532
return active;
520
533
}
521
534
@@ -527,17 +540,16 @@ namespace audio_tools {
527
540
}
528
541
529
542
// / moves to previous file
530
- virtual bool previous () {
543
+ virtual bool previous (int offset= 1 ) {
531
544
LOGD (LOG_METHOD);
532
- active = setStream (*(p_source->previousStream (+ 1 )));
545
+ active = setStream (*(p_source->previousStream (offset )));
533
546
return active;
534
547
}
535
548
536
549
// / start selected input stream
537
550
virtual bool setStream (Stream &input) {
538
551
end ();
539
552
p_out_decoding->begin ();
540
- p_source->begin ();
541
553
p_input_stream = &input;
542
554
if (p_input_stream != nullptr ) {
543
555
LOGD (" open selected stream" );
@@ -585,7 +597,7 @@ namespace audio_tools {
585
597
if (millis () > timeout) {
586
598
LOGW (" -> timeout - moving to next stream" );
587
599
// open next stream
588
- if (!next ()) {
600
+ if (!next (1 )) {
589
601
LOGD (" stream is null" );
590
602
}
591
603
}
0 commit comments