@@ -59,9 +59,9 @@ namespace audio_tools {
59
59
return selectStream (index);
60
60
}
61
61
62
- // / same as selectStream - I just prefer this name
63
- virtual Stream* selectStream (char * path, char * fileName ) {
64
- return selectStream (path,fileName );
62
+ // / Returns audio stream by path
63
+ virtual Stream* selectStream (char * path) {
64
+ return selectStream (path);
65
65
}
66
66
67
67
// / Sets the timeout which is triggering to move to the next stream. - the default value is 500 ms
@@ -216,10 +216,10 @@ namespace audio_tools {
216
216
return file ? &file : nullptr ;
217
217
}
218
218
219
- virtual Stream* selectStream (char * path, char * fileName ) override {
219
+ virtual Stream* selectStream (char * path) override {
220
220
file.close ();
221
- file = getFileByPath (path, fileName );
222
- LOGW (" -> selectStream: %s%s " , path, fileName );
221
+ file = getFileByPath (path);
222
+ LOGW (" -> selectStream: %s" , path);
223
223
return file ? &file : nullptr ;
224
224
}
225
225
@@ -282,9 +282,15 @@ namespace audio_tools {
282
282
return result;
283
283
}
284
284
285
- AudioFile getFileByPath (char * path, char * fileName ) {
285
+ AudioFile getFileByPath (char * path) {
286
286
AudioFile dir;
287
- if (!dir.open (path)) {// ("/21/" , "001.mp3")
287
+ Str inPath (path);
288
+ StrExt strPath;
289
+ StrExt strfileName;
290
+ int pos = inPath.lastIndexOf (" /" ) + 1 ;
291
+ strPath.substring (path, 0 , pos);
292
+ strfileName.substring (path, pos, inPath.length ());
293
+ if (!dir.open (strPath.c_str ())) {// ("/21/" , "001.mp3")
288
294
LOGE (" directory: %s not open" , path);
289
295
}
290
296
else
@@ -294,12 +300,12 @@ namespace audio_tools {
294
300
}
295
301
else
296
302
{
297
- if (!file.open (&dir, fileName , O_RDWR)) {
303
+ if (!file.open (&dir, strfileName. c_str () , O_RDWR)) {
298
304
LOGE (" file: %s not open" , path);
299
305
}
300
306
else
301
307
{
302
- LOGD (" -> getFileByPath: '%s': %d" , path, fileName );
308
+ LOGD (" -> getFileByPath: '%s': %d" , path, strfileName. c_str () );
303
309
}
304
310
}
305
311
}
@@ -415,6 +421,15 @@ namespace audio_tools {
415
421
return selectStream (pos);
416
422
}
417
423
424
+ // / Opens the selected url
425
+ Stream* selectStream (char * path) override {
426
+ LOGI (" selectStream: %s" , path);
427
+ if (started) actual_stream->end ();
428
+ actual_stream->begin (path, mime);
429
+ started = true ;
430
+ return actual_stream;
431
+ }
432
+
418
433
int index () {
419
434
return pos;
420
435
}
@@ -581,19 +596,22 @@ namespace audio_tools {
581
596
p_source->begin ();
582
597
meta_out.begin ();
583
598
584
- p_input_stream = p_source->selectStream (index);
585
- if (p_input_stream != nullptr ) {
586
- if (meta_active) {
587
- copier.setCallbackOnWrite (decodeMetaData, this );
599
+ if (index >= 0 ) {
600
+ p_input_stream = p_source->selectStream (index);
601
+ if (p_input_stream != nullptr ) {
602
+ if (meta_active) {
603
+ copier.setCallbackOnWrite (decodeMetaData, this );
604
+ }
605
+ copier.begin (*p_out_decoding, *p_input_stream);
606
+ timeout = millis () + p_source->timeoutAutoNext ();
607
+ active = isActive;
608
+ result = true ;
609
+ }
610
+ else {
611
+ LOGW (" -> begin: no data found" );
612
+ active = isActive;
613
+ result = false ;
588
614
}
589
- copier.begin (*p_out_decoding, *p_input_stream);
590
- timeout = millis () + p_source->timeoutAutoNext ();
591
- active = isActive;
592
- result = true ;
593
- }
594
- else {
595
- LOGW (" -> begin: no data found" );
596
- active = isActive;
597
615
}
598
616
return result;
599
617
}
@@ -647,10 +665,10 @@ namespace audio_tools {
647
665
}
648
666
649
667
// / moves to selected file
650
- virtual bool setPath (char * path, char * fileName ) {
668
+ virtual bool setPath (char * path) {
651
669
LOGD (LOG_METHOD);
652
670
previous_stream = false ;
653
- active = setStream (p_source->selectStream (path, fileName ));
671
+ active = setStream (p_source->selectStream (path));
654
672
return active;
655
673
}
656
674
@@ -713,6 +731,10 @@ namespace audio_tools {
713
731
// reset timeout
714
732
timeout = millis () + p_source->timeoutAutoNext ();
715
733
}
734
+ else
735
+ {
736
+ active = false ;
737
+ }
716
738
// move to next stream after timeout
717
739
if (p_input_stream == nullptr || millis () > timeout) {
718
740
if (autonext) {
0 commit comments