mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-15 02:40:38 +00:00
SoundPlayer: Add 'mute' methods to Player
These methods allow us to mute/unmute the player without needing to modify the volume level that it has.
This commit is contained in:
parent
fb109ab3b4
commit
8f2161c0ee
Notes:
sideshowbarker
2024-07-17 22:17:07 +09:00
Author: https://github.com/elyse0 Commit: https://github.com/SerenityOS/serenity/commit/8f2161c0ee0 Pull-request: https://github.com/SerenityOS/serenity/pull/11161 Reviewed-by: https://github.com/sin-ack ✅
4 changed files with 32 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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<Audio::Buffer>, [[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 };
|
||||
};
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<Audio::Buffer>, int sample_rate, int samples_played) override;
|
||||
|
||||
|
|
Loading…
Reference in a new issue