Skip to content

Commit f58ca3f

Browse files
committed
AudioPlayer: support for mute
1 parent f1c2ea4 commit f58ca3f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/AudioTools/CoreAudio/AudioPlayer.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,25 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
523523
on_stream_change_callback = callback;
524524
if (p_input_stream!=nullptr) callback(p_input_stream, p_reference);
525525
}
526+
527+
/// Mutes or unmutes the audio player
528+
void setMuted(bool muted) {
529+
if (muted) {
530+
if (current_volume > 0.0f) {
531+
muted_volume = current_volume;
532+
setVolume(0.0f);
533+
}
534+
} else {
535+
if (muted_volume > 0.0f) {
536+
setVolume(muted_volume);
537+
muted_volume = 0.0f;
538+
}
539+
}
540+
}
541+
542+
/// Returns true if the player is currently muted
543+
bool isMuted() { return current_volume == 0.0f; }
544+
526545

527546
protected:
528547
bool active = false;
@@ -545,6 +564,7 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
545564
uint32_t timeout = 0;
546565
int stream_increment = 1; // +1 moves forward; -1 moves backward
547566
float current_volume = -1.0f; // illegal value which will trigger an update
567+
float muted_volume = 0.0f;
548568
int delay_if_full = 100;
549569
bool is_auto_fade = true;
550570
void *p_reference = nullptr;

0 commit comments

Comments
 (0)