@@ -45,6 +45,9 @@ namespace audio_tools {
45
45
return nullptr ;
46
46
}
47
47
48
+ // / Returns previous audio stream
49
+ virtual Stream* previousStream (int offset) = 0;
50
+
48
51
// / Provides the timeout which is triggering to move to the next stream
49
52
virtual int timeoutMs () {
50
53
return 500 ;
@@ -80,11 +83,16 @@ namespace audio_tools {
80
83
return nextStreamCallback == nullptr ? nullptr : nextStreamCallback ();
81
84
}
82
85
83
- // / Returns next audio stream
86
+ // / Returns selected audio stream
84
87
virtual Stream* selectStream (int index) {
85
88
return indexStreamCallback == nullptr ? nullptr : indexStreamCallback (index);
86
89
}
87
90
91
+ // / Returns previous stream
92
+ virtual Stream* previousStream (int offset) {
93
+ LOGD (LOG_METHOD);
94
+ return previousStreamCallback == nullptr ? nullptr : previousStreamCallback ();
95
+ }
88
96
89
97
void setCallbackOnStart (void (*callback)()) {
90
98
onStartCallback = callback;
@@ -98,11 +106,15 @@ namespace audio_tools {
98
106
indexStreamCallback = callback;
99
107
}
100
108
109
+ void setCallbackPreviousStream (Stream* (*callback)()) {
110
+ previousStreamCallback = callback;
111
+ }
112
+
101
113
protected:
102
114
void (*onStartCallback)() = nullptr ;
103
115
Stream* (*nextStreamCallback)() = nullptr ;
104
116
Stream* (*indexStreamCallback)(int index) = nullptr ;
105
-
117
+ Stream* (*previousStreamCallback)() = nullptr ;
106
118
};
107
119
108
120
#ifdef USE_SDFAT
@@ -286,14 +298,20 @@ namespace audio_tools {
286
298
}
287
299
return actual_stream;
288
300
}
289
- // / Opens the next url from the array
301
+
302
+ // / Opens the selected url from the array
290
303
Stream* selectStream (int Station) {
291
304
// pos += offset;
292
305
pos = Station;
293
- if (pos < 0 || pos >= max ) {
306
+ if (pos < 0 ) {
294
307
pos = 0 ;
308
+ LOGI (" array out of limits: %d -> %s" , Station, pos);
295
309
}
296
- LOGI (" nextStream: %d -> %s" , pos, urlArray[pos]);
310
+ if (pos >= max) {
311
+ pos = max-1 ;
312
+ LOGI (" array out of limits: %d -> %s" , Station, pos);
313
+ }
314
+ LOGI (" selectStream: %d -> %s" , pos, urlArray[pos]);
297
315
if (Station != 0 || actual_stream == nullptr ) {
298
316
if (started) actual_stream->end ();
299
317
actual_stream->begin (urlArray[pos], mime);
@@ -302,6 +320,20 @@ namespace audio_tools {
302
320
return actual_stream;
303
321
}
304
322
323
+ // / Opens the Previous url from the array
324
+ Stream* previousStream (int offset) {
325
+ pos -= offset;
326
+ if (pos < 0 || pos >= max) {
327
+ pos = max - 1 ;
328
+ }
329
+ LOGI (" previousStream: %d -> %s" , pos, urlArray[pos]);
330
+ if (offset != 0 || actual_stream == nullptr ) {
331
+ if (started) actual_stream->end ();
332
+ actual_stream->begin (urlArray[pos], mime);
333
+ started = true ;
334
+ }
335
+ return actual_stream;
336
+ }
305
337
306
338
void setTimeoutMs (int millisec) {
307
339
timeout = millisec;
@@ -532,13 +564,20 @@ namespace audio_tools {
532
564
return active;
533
565
}
534
566
535
- // / moves to next file
567
+ // / moves to selected file
536
568
virtual bool setIndex (int idx) {
537
569
LOGD (LOG_METHOD);
538
570
active = setStream (*(p_source->selectStream (idx)));
539
571
return active;
540
572
}
541
573
574
+ // / moves to previous file
575
+ virtual bool previous () {
576
+ LOGD (LOG_METHOD);
577
+ active = setStream (*(p_source->previousStream (+1 )));
578
+ return active;
579
+ }
580
+
542
581
// / start selected input stream
543
582
virtual bool setStream (Stream &input) {
544
583
end ();
@@ -553,7 +592,6 @@ namespace audio_tools {
553
592
return p_input_stream != nullptr ;
554
593
}
555
594
556
-
557
595
// / determines if the player is active
558
596
virtual bool isActive () {
559
597
return active;
@@ -611,7 +649,6 @@ namespace audio_tools {
611
649
volume_out.setVolumeControl (vc);
612
650
}
613
651
614
-
615
652
protected:
616
653
bool active = false ;
617
654
AudioSource* p_source = nullptr ;
@@ -628,7 +665,6 @@ namespace audio_tools {
628
665
uint32_t timeout = 0 ;
629
666
float current_volume = -1 ; // illegal value which will trigger an update
630
667
631
-
632
668
// / Callback implementation which writes to metadata
633
669
static void decodeMetaData (void * obj, void * data, size_t len) {
634
670
LOGD (LOG_METHOD);
0 commit comments