Add a cmake option to use phonon even on unix. Also fix a strange bug with the phonon backend that stopped the track slider from working.

This commit is contained in:
David Sansome 2010-03-30 00:38:32 +00:00
parent 96802bdf6e
commit ef9780b44e
5 changed files with 26 additions and 9 deletions

View File

@ -10,6 +10,13 @@ if (CMAKE_FIND_ROOT_PATH)
set(QT_PHONON_INCLUDE_DIR ${CMAKE_FIND_ROOT_PATH}/include/phonon) set(QT_PHONON_INCLUDE_DIR ${CMAKE_FIND_ROOT_PATH}/include/phonon)
endif (CMAKE_FIND_ROOT_PATH) endif (CMAKE_FIND_ROOT_PATH)
option(FORCE_PHONON "Use the Phonon audio backend even on Unix")
if (FORCE_PHONON OR WIN32)
set(USE_PHONON 1)
add_definitions(-DUSE_PHONON)
endif (FORCE_PHONON OR WIN32)
find_package(Qt4 REQUIRED) find_package(Qt4 REQUIRED)
set(QT_USE_QTOPENGL 1) set(QT_USE_QTOPENGL 1)
set(QT_USE_QTSQL 1) set(QT_USE_QTSQL 1)
@ -18,9 +25,9 @@ set(QT_USE_QTXML 1)
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
set(QT_USE_QTDBUS 1) set(QT_USE_QTDBUS 1)
endif(UNIX AND NOT APPLE) endif(UNIX AND NOT APPLE)
if(WIN32) if(USE_PHONON)
set(QT_USE_PHONON 1) set(QT_USE_PHONON 1)
endif(WIN32) endif(USE_PHONON)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
find_package(Boost REQUIRED) find_package(Boost REQUIRED)

View File

@ -191,13 +191,13 @@ endforeach(QM-FILE)
file(APPEND ${CLEMENTINE-QM-RESOURCE} "</qresource></RCC>") file(APPEND ${CLEMENTINE-QM-RESOURCE} "</qresource></RCC>")
# Audio engine - phonon on windows, xine elsewhere # Audio engine - phonon on windows, xine elsewhere
if(WIN32) if(USE_PHONON)
set(CLEMENTINE-SOURCES ${CLEMENTINE-SOURCES} phononengine.cpp) set(CLEMENTINE-SOURCES ${CLEMENTINE-SOURCES} phononengine.cpp)
set(CLEMENTINE-MOC-HEADERS ${CLEMENTINE-MOC-HEADERS} phononengine.h) set(CLEMENTINE-MOC-HEADERS ${CLEMENTINE-MOC-HEADERS} phononengine.h)
else(WIN32) else(USE_PHONON)
set(CLEMENTINE-SOURCES ${CLEMENTINE-SOURCES} xine-engine.cpp xine-scope.c) set(CLEMENTINE-SOURCES ${CLEMENTINE-SOURCES} xine-engine.cpp xine-scope.c)
set(CLEMENTINE-MOC-HEADERS ${CLEMENTINE-MOC-HEADERS} xine-engine.h) set(CLEMENTINE-MOC-HEADERS ${CLEMENTINE-MOC-HEADERS} xine-engine.h)
endif(WIN32) endif(USE_PHONON)
# OSD and DBus. # OSD and DBus.
if(APPLE) if(APPLE)

View File

@ -21,7 +21,8 @@
PhononEngine::PhononEngine() PhononEngine::PhononEngine()
: media_object_(new Phonon::MediaObject(this)), : 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)) state_timer_(new QTimer(this)),
seek_offset_(-1)
{ {
Phonon::createPath(media_object_, audio_output_); Phonon::createPath(media_object_, audio_output_);
@ -52,6 +53,10 @@ bool PhononEngine::load(const QUrl &url, bool stream) {
} }
bool PhononEngine::play(uint offset) { bool PhononEngine::play(uint offset) {
// The seek happens in PhononStateChanged - phonon doesn't seem to change
// currentTime() if we seek before we start playing :S
seek_offset_ = offset;
media_object_->play(); media_object_->play();
return true; return true;
} }
@ -109,12 +114,15 @@ void PhononEngine::PhononStateChanged(Phonon::State new_state) {
if (new_state == Phonon::ErrorState) { if (new_state == Phonon::ErrorState) {
emit error(media_object_->errorString()); emit error(media_object_->errorString());
} }
if (new_state == Phonon::PlayingState && seek_offset_ != -1) {
media_object_->seek(seek_offset_);
seek_offset_ = -1;
}
// Don't emit the state change straight away // Don't emit the state change straight away
state_timer_->start(100); state_timer_->start(100);
} }
void PhononEngine::StateTimeoutExpired() { void PhononEngine::StateTimeoutExpired() {
qDebug() << state();
emit stateChanged(state()); emit stateChanged(state());
} }

View File

@ -60,6 +60,8 @@ class PhononEngine : public Engine::Base {
Phonon::AudioOutput* audio_output_; Phonon::AudioOutput* audio_output_;
QTimer* state_timer_; QTimer* state_timer_;
qint64 seek_offset_;
}; };
#endif // PHONONENGINE_H #endif // PHONONENGINE_H

View File

@ -24,7 +24,7 @@
# include <QDBusConnection> # include <QDBusConnection>
#endif #endif
#ifdef Q_OS_WIN32 #ifdef USE_PHONON
# include "phononengine.h" # include "phononengine.h"
#else #else
# include "xine-engine.h" # include "xine-engine.h"
@ -65,7 +65,7 @@ Player::Player(Playlist* playlist, LastFMService* lastfm, QObject* parent)
engine_(NULL), engine_(NULL),
init_engine_watcher_(new QFutureWatcher<bool>(this)) init_engine_watcher_(new QFutureWatcher<bool>(this))
{ {
#ifdef Q_OS_WIN32 #ifdef USE_PHONON
engine_ = new PhononEngine; engine_ = new PhononEngine;
#else #else
engine_ = new XineEngine; engine_ = new XineEngine;