1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 16:55:09 +00:00

SoundPlayer: Fix glitchy visualization on pause/stop

Previously when pausing or stoping a track in SoundPlayer,
the visualizations would glitch out. This was caused by them
being updated with the same buffer over and over.
With this patch a pause action will freeze the visualization at the
point of the pause and a stop action will reset the visualization
so it displays nothing until a track is started.
This commit is contained in:
Joel Petersson 2023-05-01 19:07:37 +02:00 committed by Jelle Raaijmakers
parent f1d8e55168
commit e98315de6b
2 changed files with 6 additions and 1 deletions

View file

@ -21,7 +21,8 @@ Player::Player(Audio::ConnectionToServer& audio_client_connection)
auto played_seconds = samples_played / sample_rate; auto played_seconds = samples_played / sample_rate;
time_elapsed(played_seconds); time_elapsed(played_seconds);
sound_buffer_played(m_playback_manager.current_buffer(), m_playback_manager.device_sample_rate(), samples_played); if (play_state() == PlayState::Playing)
sound_buffer_played(m_playback_manager.current_buffer(), m_playback_manager.device_sample_rate(), samples_played);
}; };
m_playback_manager.on_finished_playing = [&]() { m_playback_manager.on_finished_playing = [&]() {
set_play_state(PlayState::Stopped); set_play_state(PlayState::Stopped);

View file

@ -213,6 +213,10 @@ void SoundPlayerWidgetAdvancedView::play_state_changed(Player::PlayState state)
m_stop_action->set_enabled(state != PlayState::Stopped && state != PlayState::NoFileLoaded); m_stop_action->set_enabled(state != PlayState::Stopped && state != PlayState::NoFileLoaded);
m_playback_progress_slider->set_enabled(state != PlayState::NoFileLoaded); m_playback_progress_slider->set_enabled(state != PlayState::NoFileLoaded);
if (state == PlayState::Stopped) {
m_playback_progress_slider->set_value(m_playback_progress_slider->min(), GUI::AllowCallback::No);
m_visualization->reset_buffer();
}
} }
void SoundPlayerWidgetAdvancedView::loop_mode_changed(Player::LoopMode) void SoundPlayerWidgetAdvancedView::loop_mode_changed(Player::LoopMode)