Player: Use timer for saving volume

Fixes #1272
This commit is contained in:
Jonas Kvinge 2024-04-02 17:16:29 +02:00
parent c00d95242d
commit f5547f093e
2 changed files with 10 additions and 0 deletions

View File

@ -80,6 +80,7 @@ Player::Player(Application *app, QObject *parent)
#endif #endif
analyzer_(nullptr), analyzer_(nullptr),
equalizer_(nullptr), equalizer_(nullptr),
timer_save_volume_(new QTimer(this)),
stream_change_type_(EngineBase::TrackChangeType::First), stream_change_type_(EngineBase::TrackChangeType::First),
autoscroll_(Playlist::AutoScroll::Maybe), autoscroll_(Playlist::AutoScroll::Maybe),
last_state_(EngineBase::State::Empty), last_state_(EngineBase::State::Empty),
@ -100,6 +101,10 @@ Player::Player(Application *app, QObject *parent)
CreateEngine(enginetype); CreateEngine(enginetype);
timer_save_volume_->setSingleShot(true);
timer_save_volume_->setInterval(5000);
QObject::connect(timer_save_volume_, &QTimer::timeout, this, &Player::SaveVolume);
} }
EngineBase::Type Player::CreateEngine(EngineBase::Type enginetype) { EngineBase::Type Player::CreateEngine(EngineBase::Type enginetype) {
@ -659,6 +664,7 @@ void Player::SetVolumeFromSlider(const int value) {
volume_ = volume; volume_ = volume;
engine_->SetVolume(volume); engine_->SetVolume(volume);
emit VolumeChanged(volume); emit VolumeChanged(volume);
timer_save_volume_->start();
} }
} }
@ -669,6 +675,7 @@ void Player::SetVolumeFromEngine(const uint volume) {
if (new_volume != volume_) { if (new_volume != volume_) {
volume_ = new_volume; volume_ = new_volume;
emit VolumeChanged(new_volume); emit VolumeChanged(new_volume);
timer_save_volume_->start();
} }
} }
@ -680,6 +687,7 @@ void Player::SetVolume(const uint volume) {
volume_ = new_volume; volume_ = new_volume;
engine_->SetVolume(new_volume); engine_->SetVolume(new_volume);
emit VolumeChanged(new_volume); emit VolumeChanged(new_volume);
timer_save_volume_->start();
} }
} }

View File

@ -39,6 +39,7 @@
#include "playlist/playlistitem.h" #include "playlist/playlistitem.h"
#include "settings/behavioursettingspage.h" #include "settings/behavioursettingspage.h"
class QTimer;
class Application; class Application;
class Song; class Song;
class AnalyzerContainer; class AnalyzerContainer;
@ -223,6 +224,7 @@ class Player : public PlayerInterface {
#endif #endif
AnalyzerContainer *analyzer_; AnalyzerContainer *analyzer_;
SharedPtr<Equalizer> equalizer_; SharedPtr<Equalizer> equalizer_;
QTimer *timer_save_volume_;
PlaylistItemPtr current_item_; PlaylistItemPtr current_item_;