From 0ba179f54fbf81edb6fb1e95c9ca55e751e3af0d Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sun, 21 Feb 2010 21:23:06 +0000 Subject: [PATCH] Phonon engine works --- src/phononengine.cpp | 31 ++++++++++++++++++++++++++++--- src/phononengine.h | 15 +++++++++++++-- src/src.pro | 6 +++--- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/phononengine.cpp b/src/phononengine.cpp index 7ae960764..51aedd40f 100644 --- a/src/phononengine.cpp +++ b/src/phononengine.cpp @@ -1,10 +1,19 @@ #include "phononengine.h" +#include + PhononEngine::PhononEngine() : media_object_(new Phonon::MediaObject(this)), - audio_output_(new Phonon::AudioOutput(Phonon::MusicCategory, this)) + audio_output_(new Phonon::AudioOutput(Phonon::MusicCategory, this)), + state_timer_(new QTimer(this)) { Phonon::createPath(media_object_, audio_output_); + + connect(media_object_, SIGNAL(finished()), SLOT(PhononFinished())); + connect(media_object_, SIGNAL(stateChanged(Phonon::State,Phonon::State)), SLOT(PhononStateChanged(Phonon::State))); + + state_timer_->setSingleShot(true); + connect(state_timer_, SIGNAL(timeout()), SLOT(StateTimeoutExpired())); } PhononEngine::~PhononEngine() { @@ -46,8 +55,6 @@ void PhononEngine::unpause() { Engine::State PhononEngine::state() const { switch (media_object_->state()) { case Phonon::LoadingState: - return Engine::Idle; - case Phonon::PlayingState: case Phonon::BufferingState: return Engine::Playing; @@ -77,3 +84,21 @@ void PhononEngine::seek(uint ms) { void PhononEngine::setVolumeSW(uint percent) { audio_output_->setVolume(qreal(percent) / 100.0); } + +void PhononEngine::PhononFinished() { + emit trackEnded(); +} + +void PhononEngine::PhononStateChanged(Phonon::State new_state) { + if (new_state == Phonon::ErrorState) { + emit error(media_object_->errorString()); + } + + // Don't emit the state change straight away + state_timer_->start(100); +} + +void PhononEngine::StateTimeoutExpired() { + qDebug() << state(); + emit stateChanged(state()); +} diff --git a/src/phononengine.h b/src/phononengine.h index 593566fd6..a8a830f54 100644 --- a/src/phononengine.h +++ b/src/phononengine.h @@ -3,10 +3,14 @@ #include "enginebase.h" -#include -#include +#include +#include + +class QTimer; class PhononEngine : public Engine::Base { + Q_OBJECT + public: PhononEngine(); ~PhononEngine(); @@ -30,9 +34,16 @@ class PhononEngine : public Engine::Base { protected: void setVolumeSW( uint percent ); + private slots: + void PhononFinished(); + void PhononStateChanged(Phonon::State new_state); + void StateTimeoutExpired(); + private: Phonon::MediaObject* media_object_; Phonon::AudioOutput* audio_output_; + + QTimer* state_timer_; }; #endif // PHONONENGINE_H diff --git a/src/src.pro b/src/src.pro index fb78a71dd..6fb1787f8 100644 --- a/src/src.pro +++ b/src/src.pro @@ -185,9 +185,9 @@ SOURCES += ../3rdparty/qtsingleapplication/qtlocalpeer.cpp SOURCES += ../3rdparty/qtsingleapplication/qtlockedfile.cpp unix:!fedora-win32-cross:SOURCES += ../3rdparty/qtsingleapplication/qtlockedfile_unix.cpp win32|fedora-win32-cross:SOURCES += ../3rdparty/qtsingleapplication/qtlockedfile_win.cpp -win32|fedora-win32-cross:# Hide the console on windows -: -LIBS += -Wl,-subsystem,windows + +# Hide the console on windows +win32|fedora-win32-cross:LIBS += -Wl,-subsystem,windows # Installs target.path = $${install_prefix}/bin/