@@ -40,7 +40,10 @@ namespace audio_tools {
40
40
virtual Stream* nextStream (int offset) = 0;
41
41
42
42
// / Returns next audio stream
43
- virtual Stream* selectStream (int station) = 0;
43
+ virtual Stream* selectStream (int station) {
44
+ LOGE (" Not Supported!" );
45
+ return nullptr ;
46
+ }
44
47
45
48
// / Provides the timeout which is triggering to move to the next stream
46
49
virtual int timeoutMs () {
@@ -280,6 +283,7 @@ namespace audio_tools {
280
283
return actual_stream;
281
284
}
282
285
286
+
283
287
void setTimeoutMs (int millisec) {
284
288
timeout = millisec;
285
289
}
@@ -419,7 +423,7 @@ namespace audio_tools {
419
423
}
420
424
421
425
// / (Re)Starts the playing of the music (from the beginning)
422
- virtual bool begin (int station = 1 , bool isActive = true ) {
426
+ virtual bool begin (bool isActive = true ) {
423
427
LOGD (LOG_METHOD);
424
428
bool result = false ;
425
429
@@ -428,7 +432,33 @@ namespace audio_tools {
428
432
p_source->begin ();
429
433
meta_out.begin ();
430
434
431
- p_input_stream = p_source->selectStream (station);
435
+ p_input_stream = p_source->nextStream (1 );
436
+ if (p_input_stream != nullptr ) {
437
+ if (meta_active) {
438
+ copier.setCallbackOnWrite (decodeMetaData, this );
439
+ }
440
+ copier.begin (*p_out_decoding, *p_input_stream);
441
+ timeout = millis () + p_source->timeoutMs ();
442
+ active = isActive;
443
+ result = true ;
444
+ }
445
+ else {
446
+ LOGW (" -> begin: no data found" );
447
+ }
448
+ return result;
449
+ }
450
+
451
+ // / (Re)Starts the playing of the music (from the beginning)
452
+ virtual bool begin (int index, bool isActive = true ) {
453
+ LOGD (LOG_METHOD);
454
+ bool result = false ;
455
+
456
+ // start dependent objects
457
+ p_out_decoding->begin ();
458
+ p_source->begin ();
459
+ meta_out.begin ();
460
+
461
+ p_input_stream = p_source->selectStream (index);
432
462
if (p_input_stream != nullptr ) {
433
463
if (meta_active) {
434
464
copier.setCallbackOnWrite (decodeMetaData, this );
@@ -477,17 +507,34 @@ namespace audio_tools {
477
507
}
478
508
479
509
// / moves to next file
480
- virtual void next () {
510
+ virtual bool next () {
481
511
LOGD (LOG_METHOD);
482
- active = startNextStream ();
512
+ active = setStream (*(p_source->nextStream (+1 )));
513
+ return active;
483
514
}
515
+
484
516
// / moves to next file
485
- virtual void Select (int station ) {
517
+ virtual bool setIndex (int idx ) {
486
518
LOGD (LOG_METHOD);
487
- active = startSelectedStream (station);
488
- // startSelectedStream(station);
519
+ active = setStream (*(p_source->selectStream (idx)));
520
+ return active;
521
+ }
522
+
523
+ // / start selected input stream
524
+ virtual bool setStream (Stream &input) {
525
+ end ();
526
+ p_out_decoding->begin ();
527
+ p_source->begin ();
528
+ p_input_stream = &input;
529
+ if (p_input_stream != nullptr ) {
530
+ LOGD (" open selected stream" );
531
+ meta_out.begin ();
532
+ copier.begin (*p_out_decoding, *p_input_stream);
533
+ }
534
+ return p_input_stream != nullptr ;
489
535
}
490
536
537
+
491
538
// / determines if the player is active
492
539
virtual bool isActive () {
493
540
return active;
@@ -526,7 +573,7 @@ namespace audio_tools {
526
573
if (millis () > timeout) {
527
574
LOGW (" -> timeout - moving to next stream" );
528
575
// open next stream
529
- if (!startNextStream ()) {
576
+ if (!next ()) {
530
577
LOGD (" stream is null" );
531
578
}
532
579
}
@@ -563,33 +610,6 @@ namespace audio_tools {
563
610
float current_volume = -1 ; // illegal value which will trigger an update
564
611
565
612
566
- // / start next stream
567
- virtual bool startNextStream () {
568
- end ();
569
- p_out_decoding->begin ();
570
- p_source->begin ();
571
- p_input_stream = p_source->nextStream (+1 );
572
- if (p_input_stream != nullptr ) {
573
- LOGD (" open next stream" );
574
- meta_out.begin ();
575
- copier.begin (*p_out_decoding, *p_input_stream);
576
- }
577
- return p_input_stream != nullptr ;
578
- }
579
- // / start selected stream
580
- virtual bool startSelectedStream (int station) {
581
- end ();
582
- p_out_decoding->begin ();
583
- p_source->begin ();
584
- p_input_stream = p_source->selectStream (station);
585
- if (p_input_stream != nullptr ) {
586
- LOGD (" open selected stream" );
587
- meta_out.begin ();
588
- copier.begin (*p_out_decoding, *p_input_stream);
589
- }
590
- return p_input_stream != nullptr ;
591
- }
592
-
593
613
// / Callback implementation which writes to metadata
594
614
static void decodeMetaData (void * obj, void * data, size_t len) {
595
615
LOGD (LOG_METHOD);
0 commit comments