@@ -331,6 +331,8 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
331
331
meta_out.begin ();
332
332
copier.begin (out_decoding, *p_input_stream);
333
333
}
334
+ // execute callback if defined
335
+ if (on_stream_change_callback) on_stream_change_callback (p_input_stream, p_reference);
334
336
return p_input_stream != nullptr ;
335
337
}
336
338
@@ -436,24 +438,6 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
436
438
return result;
437
439
}
438
440
439
- // / Defines the medatadata callback
440
- void setMetadataCallback (void (*callback)(MetaDataType type,
441
- const char *str, int len),
442
- ID3TypeSelection sel = SELECT_ID3) {
443
- TRACEI ();
444
- // setup metadata.
445
- if (p_source->setMetadataCallback (callback)) {
446
- // metadata is handled by source
447
- LOGI (" Using ICY Metadata" );
448
- meta_active = false ;
449
- } else {
450
- // metadata is handled here
451
- meta_out.setCallback (callback);
452
- meta_out.setFilter (sel);
453
- meta_active = true ;
454
- }
455
- }
456
-
457
441
// / Change the VolumeControl implementation
458
442
void setVolumeControl (VolumeControl &vc) {
459
443
volume_out.setVolumeControl (vc);
@@ -497,6 +481,34 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
497
481
meta_out.resize (size);
498
482
}
499
483
484
+ // / this is used to set the reference for the stream change callback
485
+ void setReference (void * ref) {
486
+ p_reference = ref;
487
+ }
488
+
489
+ // / Defines the medatadata callback
490
+ void setMetadataCallback (void (*callback)(MetaDataType type,
491
+ const char *str, int len),
492
+ ID3TypeSelection sel = SELECT_ID3) {
493
+ TRACEI ();
494
+ // setup metadata.
495
+ if (p_source->setMetadataCallback (callback)) {
496
+ // metadata is handled by source
497
+ LOGI (" Using ICY Metadata" );
498
+ meta_active = false ;
499
+ } else {
500
+ // metadata is handled here
501
+ meta_out.setCallback (callback);
502
+ meta_out.setFilter (sel);
503
+ meta_active = true ;
504
+ }
505
+ }
506
+
507
+ // / Defines a callback that is called when the stream is changed
508
+ void setOnStreamChangeCallback ( void (*callback)(Stream*stream_ptr,void * reference)){
509
+ on_stream_change_callback = callback;
510
+ }
511
+
500
512
501
513
protected:
502
514
bool active = false ;
@@ -521,6 +533,8 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
521
533
float current_volume = -1 .0f ; // illegal value which will trigger an update
522
534
int delay_if_full = 100 ;
523
535
bool is_auto_fade = true ;
536
+ void * p_reference = nullptr ;
537
+ void (*on_stream_change_callback)(Stream*stream_ptr,void * reference) = nullptr ;
524
538
525
539
void setupFade () {
526
540
if (p_final_print != nullptr ) {
0 commit comments