From 01cccc0468f0a3988d046cf0bf704303c259c41e Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sat, 11 Dec 2010 13:38:51 +0000 Subject: [PATCH] Cache the last emitted state from the engine to fix some invalid values being emitted over DBUS while a last.fm stream is buffering. Fixes issue #374 --- src/core/player.cpp | 7 ++----- src/core/player.h | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/player.cpp b/src/core/player.cpp index 844a171ff..c37159148 100644 --- a/src/core/player.cpp +++ b/src/core/player.cpp @@ -62,6 +62,7 @@ Player::Player(MainWindow* main_window, PlaylistManager* playlists, lastfm_(lastfm), engine_(CreateEngine(engine)), stream_change_type_(Engine::First), + last_state_(Engine::Empty), volume_before_mute_(50) { // Loads album art and saves it to a file in /tmp for MPRIS clients and those @@ -75,7 +76,6 @@ Player::Player(MainWindow* main_window, PlaylistManager* playlists, qDBusRegisterMetaType(); qDBusRegisterMetaType(); - //MPRIS 1.0 implementation mpris1_ = new mpris::Mpris1(this, art_loader_, this); @@ -279,6 +279,7 @@ void Player::EngineStateChanged(Engine::State state) { case Engine::Empty: case Engine::Idle: emit Stopped(); break; } + last_state_ = state; } void Player::SetVolume(int value) { @@ -298,10 +299,6 @@ int Player::GetVolume() const { return engine_->volume(); } -Engine::State Player::GetState() const { - return engine_->state(); -} - void Player::PlayAt(int index, Engine::TrackChangeType change, bool reshuffle) { if (change == Engine::Manual && engine_->position() != engine_->length()) { emit TrackSkipped(current_item_); diff --git a/src/core/player.h b/src/core/player.h index 343b0a7dc..b969c9be5 100644 --- a/src/core/player.h +++ b/src/core/player.h @@ -57,7 +57,7 @@ class Player : public QObject { void Init(); EngineBase* engine() const { return engine_.get(); } - Engine::State GetState() const; + Engine::State GetState() const { return last_state_; } int GetVolume() const; PlaylistItemPtr GetCurrentItem() const { return current_item_; } @@ -131,6 +131,7 @@ class Player : public QObject { boost::scoped_ptr engine_; Engine::TrackChangeType stream_change_type_; + Engine::State last_state_; QUrl loading_async_;