First go at a phonon engine

This commit is contained in:
David Sansome 2010-02-21 20:49:38 +00:00
parent fe45d1ee7d
commit 65ce08ae85
5 changed files with 136 additions and 20 deletions

View File

@ -29,12 +29,6 @@ int main(int argc, char *argv[]) {
// Couldn't send the message so start anyway
}
#ifdef Q_OS_WIN32
// CONFIG += console seems to fix a race condition in xine. God knows why :/
// Hide the console window here so it doen't annoy the user.
ShowWindow( GetConsoleWindow(), SW_HIDE );
#endif // Q_OS_WIN32
MainWindow w;
a.setActivationWindow(&w);

79
src/phononengine.cpp Normal file
View File

@ -0,0 +1,79 @@
#include "phononengine.h"
PhononEngine::PhononEngine()
: media_object_(new Phonon::MediaObject(this)),
audio_output_(new Phonon::AudioOutput(Phonon::MusicCategory, this))
{
Phonon::createPath(media_object_, audio_output_);
}
PhononEngine::~PhononEngine() {
delete media_object_;
delete audio_output_;
}
bool PhononEngine::init() {
return true;
}
bool PhononEngine::canDecode(const QUrl &url) const {
// TODO
return true;
}
bool PhononEngine::load(const QUrl &url, bool stream) {
media_object_->setCurrentSource(Phonon::MediaSource(url));
return true;
}
bool PhononEngine::play(uint offset) {
media_object_->play();
return true;
}
void PhononEngine::stop() {
media_object_->stop();
}
void PhononEngine::pause() {
media_object_->pause();
}
void PhononEngine::unpause() {
media_object_->play();
}
Engine::State PhononEngine::state() const {
switch (media_object_->state()) {
case Phonon::LoadingState:
return Engine::Idle;
case Phonon::PlayingState:
case Phonon::BufferingState:
return Engine::Playing;
case Phonon::PausedState:
return Engine::Paused;
case Phonon::StoppedState:
case Phonon::ErrorState:
default:
return Engine::Empty;
}
}
uint PhononEngine::position() const {
return media_object_->currentTime();
}
uint PhononEngine::length() const {
return media_object_->totalTime();
}
void PhononEngine::seek(uint ms) {
media_object_->seek(ms);
}
void PhononEngine::setVolumeSW(uint percent) {
audio_output_->setVolume(qreal(percent) / 100.0);
}

38
src/phononengine.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef PHONONENGINE_H
#define PHONONENGINE_H
#include "enginebase.h"
#include <Phonon/MediaObject>
#include <Phonon/AudioOutput>
class PhononEngine : public Engine::Base {
public:
PhononEngine();
~PhononEngine();
bool init();
bool canDecode( const QUrl &url ) const;
bool load( const QUrl &url, bool stream = false );
bool play( uint offset = 0 );
void stop();
void pause();
void unpause();
Engine::State state() const;
uint position() const;
uint length() const;
void seek( uint ms );
protected:
void setVolumeSW( uint percent );
private:
Phonon::MediaObject* media_object_;
Phonon::AudioOutput* audio_output_;
};
#endif // PHONONENGINE_H

View File

@ -1,6 +1,7 @@
#include "player.h"
#include "playlist.h"
#include "xine-engine.h"
#include "phononengine.h"
#include "lastfmservice.h"
#include <QtDebug>
@ -13,9 +14,15 @@ Player::Player(Playlist* playlist, LastFMService* lastfm, QObject* parent)
playlist_(playlist),
lastfm_(lastfm),
current_item_options_(PlaylistItem::Default),
engine_(new XineEngine),
engine_(NULL),
init_engine_watcher_(new QFutureWatcher<bool>(this))
{
//#ifdef Q_OS_WIN32
engine_ = new PhononEngine;
//#else
// engine_ = new XineEngine;
//#endif
settings_.beginGroup("Player");
SetVolume(settings_.value("volume", 50).toInt());

View File

@ -4,7 +4,8 @@ VERSION = 0.1
QT += sql \
network \
xml \
opengl
opengl \
phonon
TARGET = clementine
TEMPLATE = app
SOURCES += main.cpp \
@ -53,7 +54,8 @@ SOURCES += main.cpp \
librarydirectorymodel.cpp \
libraryconfigdialog.cpp \
lastfmconfigdialog.cpp \
about.cpp
about.cpp \
phononengine.cpp
HEADERS += mainwindow.h \
player.h \
library.h \
@ -107,7 +109,8 @@ HEADERS += mainwindow.h \
librarydirectorymodel.h \
libraryconfigdialog.h \
lastfmconfigdialog.h \
about.h
about.h \
phononengine.h
FORMS += mainwindow.ui \
libraryconfig.ui \
fileview.ui \
@ -182,14 +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
# Show console for now since it seems to fix a xine race condition :(
CONFIG += console
}
win32|fedora-win32-cross:# Hide the console on windows
:
LIBS += -Wl,-subsystem,windows
# Installs
target.path = $${install_prefix}/bin/