summaryrefslogtreecommitdiffstats
path: root/pacman-c++/audio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pacman-c++/audio.cpp')
-rw-r--r--pacman-c++/audio.cpp54
1 files changed, 36 insertions, 18 deletions
diff --git a/pacman-c++/audio.cpp b/pacman-c++/audio.cpp
index d627c75..5fb4416 100644
--- a/pacman-c++/audio.cpp
+++ b/pacman-c++/audio.cpp
@@ -15,18 +15,19 @@ AudioManager::AudioManager()
15 : m_muted(true) 15 : m_muted(true)
16{ 16{
17 if (Constants::server) 17 if (Constants::server)
18 {
18 qDebug() << "Server has no sound"; 19 qDebug() << "Server has no sound";
20 m_players.append(new AudioPlayer(this));
21 }
19 else 22 else
20 { 23 {
21 preload(); 24 preload();
22
23 AudioPlayer *firstplayer = new AudioPlayer(this); 25 AudioPlayer *firstplayer = new AudioPlayer(this);
24 firstplayer->test(m_sounds[Sound::WakaWaka]); 26 firstplayer->test(m_sounds[Sound::WakaWaka]);
25 m_working = firstplayer->m_working; 27 m_working = firstplayer->m_working;
26 m_players.append(firstplayer); 28 m_players.append(firstplayer);
27
28 m_muted = false;
29 } 29 }
30 m_muted = false;
30} 31}
31 32
32AudioManager *AudioManager::self() 33AudioManager *AudioManager::self()
@@ -97,15 +98,9 @@ AudioPlayer *AudioManager::audioPlayer()
97 return m_players.at(0); 98 return m_players.at(0);
98} 99}
99 100
100void AudioManager::play(Sound::Type sound) 101void AudioManager::play(Sound::Type sound, bool wait)
101{ 102{
102 if (!isWorking()) 103 audioPlayer()->play(sound, wait);
103 {
104 emit audioPlayer()->finished();
105 return;
106 }
107
108 audioPlayer()->play(sound);
109} 104}
110 105
111void AudioManager::enqueue(Sound::Type sound) 106void AudioManager::enqueue(Sound::Type sound)
@@ -151,11 +146,14 @@ QFile *AudioManager::sound(Sound::Type sound)
151/* --------------------------------------------------------------- */ 146/* --------------------------------------------------------------- */
152 147
153AudioPlayer::AudioPlayer(QObject *parent) 148AudioPlayer::AudioPlayer(QObject *parent)
154 : Phonon::MediaObject(parent) 149 : Phonon::MediaObject(parent), m_working(false)
155{ 150{
156 m_working = AudioManager::m_working; 151 if (!Constants::server)
157 m_output = new Phonon::AudioOutput(Phonon::MusicCategory, this); 152 {
158 Phonon::createPath(this, m_output); 153 m_working = AudioManager::m_working;
154 m_output = new Phonon::AudioOutput(Phonon::MusicCategory, this);
155 Phonon::createPath(this, m_output);
156 }
159} 157}
160 158
161bool AudioPlayer::isWorking() const 159bool AudioPlayer::isWorking() const
@@ -200,10 +198,25 @@ void AudioPlayer::play()
200 Phonon::MediaObject::play(); 198 Phonon::MediaObject::play();
201} 199}
202 200
203void AudioPlayer::play(Sound::Type sound) 201void AudioPlayer::play(Sound::Type sound, bool wait)
204{ 202{
205 setCurrentSource(Phonon::MediaSource(AudioManager::self()->sound(sound))); 203 if (m_working)
206 play(); 204 {
205 setCurrentSource(Phonon::MediaSource(AudioManager::self()->sound(sound)));
206 play();
207 }
208 else if (wait)
209 {
210 QTimer *timer = new QTimer(this);
211 timer->setSingleShot(true);
212 unsigned int interval = Sound::length[sound];
213 /* add a small delay server side only */
214 if (Constants::server)
215 interval += Constants::tick;
216 timer->setInterval(interval);
217 connect(timer, SIGNAL(timeout()), this, SLOT(finished_ex()));
218 timer->start();
219 }
207} 220}
208 221
209/* this is a simple hack to check if phonon can actually play sounds.. */ 222/* this is a simple hack to check if phonon can actually play sounds.. */
@@ -227,6 +240,11 @@ void AudioPlayer::test(QFile *testsound)
227 clear(); 240 clear();
228} 241}
229 242
243void AudioPlayer::finished_ex()
244{
245 emit finished();
246}
247
230void AudioPlayer::stateChanged_ex(Phonon::State newstate, Phonon::State /* oldstate */) 248void AudioPlayer::stateChanged_ex(Phonon::State newstate, Phonon::State /* oldstate */)
231{ 249{
232 if (newstate != Phonon::ErrorState) 250 if (newstate != Phonon::ErrorState)