diff --git a/Userland/Applications/SoundPlayer/Player.cpp b/Userland/Applications/SoundPlayer/Player.cpp index 153d7060ac..31551c5c05 100644 --- a/Userland/Applications/SoundPlayer/Player.cpp +++ b/Userland/Applications/SoundPlayer/Player.cpp @@ -99,6 +99,15 @@ void Player::set_volume(double volume) volume_changed(m_volume); } +void Player::set_mute(bool muted) +{ + if (m_muted != muted) { + m_muted = muted; + m_audio_client_connection.set_self_muted(muted); + mute_changed(muted); + } +} + void Player::set_shuffle_mode(ShuffleMode mode) { if (m_shuffle_mode != mode) { @@ -132,6 +141,16 @@ void Player::stop() set_play_state(PlayState::Stopped); } +void Player::mute() +{ + set_mute(true); +} + +void Player::toggle_mute() +{ + set_mute(!m_muted); +} + void Player::seek(int sample) { m_playback_manager.seek(sample); diff --git a/Userland/Applications/SoundPlayer/Player.h b/Userland/Applications/SoundPlayer/Player.h index d215ae6989..8635a35452 100644 --- a/Userland/Applications/SoundPlayer/Player.h +++ b/Userland/Applications/SoundPlayer/Player.h @@ -50,11 +50,16 @@ public: double volume() const { return m_volume; } void set_volume(double value); + bool is_muted() const { return m_muted; } + void set_mute(bool); + void play(); void pause(); void toggle_pause(); void stop(); void seek(int sample); + void mute(); + void toggle_mute(); virtual void play_state_changed(PlayState) = 0; virtual void loop_mode_changed(LoopMode) = 0; @@ -64,6 +69,7 @@ public: virtual void audio_load_error(StringView, StringView) = 0; virtual void shuffle_mode_changed(ShuffleMode) = 0; virtual void volume_changed(double) = 0; + virtual void mute_changed(bool) = 0; virtual void total_samples_changed(int) = 0; virtual void sound_buffer_played(RefPtr, [[maybe_unused]] int sample_rate, [[maybe_unused]] int samples_played) = 0; @@ -74,6 +80,7 @@ protected: set_loop_mode(LoopMode::None); time_elapsed(0); set_volume(1.); + set_mute(false); } private: @@ -87,4 +94,5 @@ private: String m_loaded_filename; double m_volume { 0 }; + bool m_muted { false }; }; diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp index b66f1d1ca3..b5d8ce353a 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp @@ -180,6 +180,10 @@ void SoundPlayerWidgetAdvancedView::loop_mode_changed(Player::LoopMode) { } +void SoundPlayerWidgetAdvancedView::mute_changed(bool) +{ +} + void SoundPlayerWidgetAdvancedView::sync_previous_next_buttons() { m_back_button->set_enabled(playlist().size() > 1 && !playlist().shuffling()); diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h index f73297c113..f06edc6001 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h @@ -42,6 +42,7 @@ public: virtual void playlist_loaded(StringView, bool) override; virtual void audio_load_error(StringView path, StringView error_reason) override; virtual void volume_changed(double) override; + virtual void mute_changed(bool) override; virtual void total_samples_changed(int) override; virtual void sound_buffer_played(RefPtr, int sample_rate, int samples_played) override;