Skip to content

Commit 9982b0a

Browse files
committed
AudioPlayer: new setOnStreamChangeCallback()
1 parent 1963d58 commit 9982b0a

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

src/AudioTools/CoreAudio/AudioPlayer.h

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
331331
meta_out.begin();
332332
copier.begin(out_decoding, *p_input_stream);
333333
}
334+
// execute callback if defined
335+
if (on_stream_change_callback) on_stream_change_callback(p_input_stream, p_reference);
334336
return p_input_stream != nullptr;
335337
}
336338

@@ -436,24 +438,6 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
436438
return result;
437439
}
438440

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-
457441
/// Change the VolumeControl implementation
458442
void setVolumeControl(VolumeControl &vc) {
459443
volume_out.setVolumeControl(vc);
@@ -497,6 +481,34 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
497481
meta_out.resize(size);
498482
}
499483

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+
500512

501513
protected:
502514
bool active = false;
@@ -521,6 +533,8 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
521533
float current_volume = -1.0f; // illegal value which will trigger an update
522534
int delay_if_full = 100;
523535
bool is_auto_fade = true;
536+
void* p_reference = nullptr;
537+
void(*on_stream_change_callback)(Stream*stream_ptr,void* reference) = nullptr;
524538

525539
void setupFade() {
526540
if (p_final_print != nullptr) {

0 commit comments

Comments
 (0)