diff options
| author | manuel <manuel@mausz.at> | 2011-05-11 17:38:29 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-05-11 17:38:29 +0200 |
| commit | ca29fc0babe8fc985a9e4656f80fc7faec4ac8a5 (patch) | |
| tree | fb48f74ffcddcd8b260ebf78062623427aeda862 /pacman-c++/phononplayer/phononplayer.cpp | |
| parent | 535c342a2f28e0a1e90010b2f0ff4018eeeb200a (diff) | |
| download | foop-ca29fc0babe8fc985a9e4656f80fc7faec4ac8a5.tar.gz foop-ca29fc0babe8fc985a9e4656f80fc7faec4ac8a5.tar.bz2 foop-ca29fc0babe8fc985a9e4656f80fc7faec4ac8a5.zip | |
- fix audio plugin and make that a real interface
- that fixes a duplicate statis audiomanager (1x pacman, 1x audio plugin) on windows
- display won/lost dialog upon gameend
Diffstat (limited to 'pacman-c++/phononplayer/phononplayer.cpp')
| -rw-r--r-- | pacman-c++/phononplayer/phononplayer.cpp | 37 |
1 files changed, 29 insertions, 8 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 | ||
