diff options
Diffstat (limited to 'pacman-c++/phononplayer')
| -rw-r--r-- | pacman-c++/phononplayer/phononplayer.cpp | 37 | ||||
| -rw-r--r-- | pacman-c++/phononplayer/phononplayer.h | 14 | ||||
| -rw-r--r-- | pacman-c++/phononplayer/phononplayer.pro | 3 |
3 files changed, 40 insertions, 14 deletions
diff --git a/pacman-c++/phononplayer/phononplayer.cpp b/pacman-c++/phononplayer/phononplayer.cpp index 1f537d6..3d7b446 100644 --- a/pacman-c++/phononplayer/phononplayer.cpp +++ b/pacman-c++/phononplayer/phononplayer.cpp | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #include "phononplayer.h" | 1 | #include "phononplayer.h" |
| 2 | #include "audio.h" | ||
| 2 | #include <QtPlugin> | 3 | #include <QtPlugin> |
| 3 | #include <QCoreApplication> | 4 | #include <QCoreApplication> |
| 4 | 5 | ||
| @@ -12,9 +13,8 @@ Q_EXPORT_PLUGIN2(phononplayer, PhononPlayerFactory) | |||
| 12 | /* --------------------------------------------------------------- */ | 13 | /* --------------------------------------------------------------- */ |
| 13 | 14 | ||
| 14 | PhononPlayer::PhononPlayer(QObject *parent) | 15 | PhononPlayer::PhononPlayer(QObject *parent) |
| 15 | : AudioPlayer(parent) | 16 | : AudioPlayer(parent), m_working(false) |
| 16 | { | 17 | { |
| 17 | m_working = AudioManager::isWorking(); | ||
| 18 | m_player = new Phonon::MediaObject(this); | 18 | m_player = new Phonon::MediaObject(this); |
| 19 | m_output = new Phonon::AudioOutput(Phonon::MusicCategory, this); | 19 | m_output = new Phonon::AudioOutput(Phonon::MusicCategory, this); |
| 20 | Phonon::createPath(m_player, m_output); | 20 | Phonon::createPath(m_player, m_output); |
| @@ -39,25 +39,36 @@ bool PhononPlayer::isMuted() const | |||
| 39 | 39 | ||
| 40 | void PhononPlayer::play() | 40 | void PhononPlayer::play() |
| 41 | { | 41 | { |
| 42 | if (!m_working) | ||
| 43 | return; | ||
| 42 | m_player->play(); | 44 | m_player->play(); |
| 43 | } | 45 | } |
| 44 | 46 | ||
| 45 | void PhononPlayer::play(Sound::Type sound) | 47 | void PhononPlayer::play(QFile *sound, unsigned int length) |
| 46 | { | 48 | { |
| 47 | if (!m_working) | 49 | if (!m_working) |
| 48 | return; | 50 | return; |
| 49 | m_player->setCurrentSource(Phonon::MediaSource(AudioManager::self()->sound(sound))); | 51 | setSource(sound, length); |
| 50 | play(); | 52 | play(); |
| 51 | } | 53 | } |
| 52 | 54 | ||
| 55 | void PhononPlayer::setSource(QFile *sound, unsigned int /* length */) | ||
| 56 | { | ||
| 57 | if (!m_working) | ||
| 58 | return; | ||
| 59 | m_player->setCurrentSource(Phonon::MediaSource(sound)); | ||
| 60 | } | ||
| 61 | |||
| 53 | bool PhononPlayer::isPlaying() | 62 | bool PhononPlayer::isPlaying() |
| 54 | { | 63 | { |
| 55 | return m_player->state() == Phonon::PlayingState; | 64 | return m_player->state() == Phonon::PlayingState; |
| 56 | } | 65 | } |
| 57 | 66 | ||
| 58 | void PhononPlayer::enqueue(Sound::Type sound) | 67 | void PhononPlayer::enqueue(QFile *sound, unsigned int /* length */) |
| 59 | { | 68 | { |
| 60 | m_player->enqueue(Phonon::MediaSource(AudioManager::self()->sound(sound))); | 69 | if (!m_working) |
| 70 | return; | ||
| 71 | m_player->enqueue(Phonon::MediaSource(sound)); | ||
| 61 | } | 72 | } |
| 62 | 73 | ||
| 63 | void PhononPlayer::pause() | 74 | void PhononPlayer::pause() |
| @@ -96,12 +107,22 @@ void PhononPlayer::setPrefinishMark(qint32 msecToEnd) | |||
| 96 | m_player->setPrefinishMark(msecToEnd); | 107 | m_player->setPrefinishMark(msecToEnd); |
| 97 | } | 108 | } |
| 98 | 109 | ||
| 110 | void PhononPlayer::seek(qint64 time) | ||
| 111 | { | ||
| 112 | m_player->seek(time); | ||
| 113 | } | ||
| 114 | |||
| 115 | void PhononPlayer::setWorking(bool working) | ||
| 116 | { | ||
| 117 | m_working = working; | ||
| 118 | } | ||
| 119 | |||
| 99 | /* this is a simple hack to check if phonon can actually play sounds.. */ | 120 | /* this is a simple hack to check if phonon can actually play sounds.. */ |
| 100 | void PhononPlayer::test(QFile *testsound, qint32 length) | 121 | void PhononPlayer::test(QFile *sound, unsigned int length) |
| 101 | { | 122 | { |
| 102 | m_player->stop(); | 123 | m_player->stop(); |
| 103 | m_output->setVolume(0); | 124 | m_output->setVolume(0); |
| 104 | m_player->setCurrentSource(Phonon::MediaSource(testsound)); | 125 | m_player->setCurrentSource(Phonon::MediaSource(sound)); |
| 105 | connect(m_player, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged_ex(Phonon::State, Phonon::State))); | 126 | connect(m_player, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged_ex(Phonon::State, Phonon::State))); |
| 106 | m_player->play(); | 127 | m_player->play(); |
| 107 | 128 | ||
diff --git a/pacman-c++/phononplayer/phononplayer.h b/pacman-c++/phononplayer/phononplayer.h index ca56726..8b9ab06 100644 --- a/pacman-c++/phononplayer/phononplayer.h +++ b/pacman-c++/phononplayer/phononplayer.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #ifndef PHONONPLAYER_H | 1 | #ifndef PHONONPLAYER_H |
| 2 | #define PHONONPLAYER_H | 2 | #define PHONONPLAYER_H |
| 3 | 3 | ||
| 4 | #include "audio.h" | 4 | #include "audiointerface.h" |
| 5 | #include <QObject> | 5 | #include <QObject> |
| 6 | #include <QFile> | 6 | #include <QFile> |
| 7 | #include <QThread> | 7 | #include <QThread> |
| @@ -25,6 +25,7 @@ class PhononPlayer | |||
| 25 | { | 25 | { |
| 26 | Q_OBJECT | 26 | Q_OBJECT |
| 27 | friend class AudioManager; | 27 | friend class AudioManager; |
| 28 | friend class PhononPlayerFactory; | ||
| 28 | 29 | ||
| 29 | private: | 30 | private: |
| 30 | class Sleeper | 31 | class Sleeper |
| @@ -37,14 +38,11 @@ private: | |||
| 37 | }; | 38 | }; |
| 38 | 39 | ||
| 39 | public: | 40 | public: |
| 40 | PhononPlayer(QObject *parent = 0); | ||
| 41 | virtual bool isWorking() const; | 41 | virtual bool isWorking() const; |
| 42 | virtual void setMuted(bool mute = true); | 42 | virtual void setMuted(bool mute = true); |
| 43 | virtual bool isMuted() const; | 43 | virtual bool isMuted() const; |
| 44 | virtual void play(); | 44 | virtual void play(); |
| 45 | virtual void play(Sound::Type sound); | ||
| 46 | virtual bool isPlaying(); | 45 | virtual bool isPlaying(); |
| 47 | virtual void enqueue(Sound::Type sound); | ||
| 48 | virtual void pause(); | 46 | virtual void pause(); |
| 49 | virtual bool isPaused(); | 47 | virtual bool isPaused(); |
| 50 | virtual void stop(); | 48 | virtual void stop(); |
| @@ -52,9 +50,15 @@ public: | |||
| 52 | virtual void clear(); | 50 | virtual void clear(); |
| 53 | virtual void clearQueue(); | 51 | virtual void clearQueue(); |
| 54 | virtual void setPrefinishMark(qint32 msecToEnd); | 52 | virtual void setPrefinishMark(qint32 msecToEnd); |
| 53 | virtual void seek(qint64 time); | ||
| 55 | 54 | ||
| 56 | protected: | 55 | protected: |
| 57 | void test(QFile *testsound, qint32 length); | 56 | PhononPlayer(QObject *parent = 0); |
| 57 | virtual void setWorking(bool working = true); | ||
| 58 | void test(QFile *sound, unsigned int length); | ||
| 59 | virtual void play(QFile *sound, unsigned int length); | ||
| 60 | virtual void setSource(QFile *sound, unsigned int length); | ||
| 61 | virtual void enqueue(QFile *sound, unsigned int length); | ||
| 58 | 62 | ||
| 59 | protected slots: | 63 | protected slots: |
| 60 | virtual void prefinishMarkReached_ex(qint32 mark); | 64 | virtual void prefinishMarkReached_ex(qint32 mark); |
diff --git a/pacman-c++/phononplayer/phononplayer.pro b/pacman-c++/phononplayer/phononplayer.pro index 9482454..a11626c 100644 --- a/pacman-c++/phononplayer/phononplayer.pro +++ b/pacman-c++/phononplayer/phononplayer.pro | |||
| @@ -8,4 +8,5 @@ QT += phonon | |||
| 8 | include(../common.pri) | 8 | include(../common.pri) |
| 9 | 9 | ||
| 10 | SOURCES += phononplayer.cpp | 10 | SOURCES += phononplayer.cpp |
| 11 | HEADERS += phononplayer.h | 11 | HEADERS += phononplayer.h \ |
| 12 | ../common/audiointerface.h | ||
