diff options
Diffstat (limited to 'pacman-c++/audioplayer.cpp')
| -rw-r--r-- | pacman-c++/audioplayer.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/pacman-c++/audioplayer.cpp b/pacman-c++/audioplayer.cpp index 238e05d..c360a23 100644 --- a/pacman-c++/audioplayer.cpp +++ b/pacman-c++/audioplayer.cpp | |||
| @@ -29,11 +29,12 @@ public: | |||
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | // the universe's only audio player | 31 | // the universe's only audio player |
| 32 | AudioPlayer *AudioPlayer::m_instance = 0; | 32 | AudioPlayer *AudioPlayer::m_instance = NULL; |
| 33 | 33 | ||
| 34 | AudioPlayer::AudioPlayer() | 34 | AudioPlayer::AudioPlayer() |
| 35 | : m_working(false) | 35 | : m_working(false) |
| 36 | { | 36 | { |
| 37 | #ifndef SERVER | ||
| 37 | m_player = new Phonon::MediaObject(this); | 38 | m_player = new Phonon::MediaObject(this); |
| 38 | connect(m_player, SIGNAL(finished()), this, SLOT(finished_p())); | 39 | connect(m_player, SIGNAL(finished()), this, SLOT(finished_p())); |
| 39 | connect(m_player, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish_p())); | 40 | connect(m_player, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish_p())); |
| @@ -44,7 +45,6 @@ AudioPlayer::AudioPlayer() | |||
| 44 | Phonon::createPath(m_player, m_output); | 45 | Phonon::createPath(m_player, m_output); |
| 45 | 46 | ||
| 46 | preload(); | 47 | preload(); |
| 47 | #ifndef SERVER | ||
| 48 | test(); | 48 | test(); |
| 49 | #endif // SERVER | 49 | #endif // SERVER |
| 50 | } | 50 | } |
| @@ -63,26 +63,32 @@ bool AudioPlayer::isWorking() const | |||
| 63 | 63 | ||
| 64 | void AudioPlayer::stop() | 64 | void AudioPlayer::stop() |
| 65 | { | 65 | { |
| 66 | if (!isWorking()) | ||
| 67 | return; | ||
| 66 | m_player->stop(); | 68 | m_player->stop(); |
| 67 | } | 69 | } |
| 68 | 70 | ||
| 69 | void AudioPlayer::setMuted(bool mute) | 71 | void AudioPlayer::setMuted(bool mute) |
| 70 | { | 72 | { |
| 73 | if (!isWorking()) | ||
| 74 | return; | ||
| 71 | m_output->setMuted(mute); | 75 | m_output->setMuted(mute); |
| 72 | } | 76 | } |
| 73 | 77 | ||
| 74 | bool AudioPlayer::isMuted() const | 78 | bool AudioPlayer::isMuted() const |
| 75 | { | 79 | { |
| 80 | if (!isWorking()) | ||
| 81 | return true; | ||
| 76 | return m_output->isMuted(); | 82 | return m_output->isMuted(); |
| 77 | } | 83 | } |
| 78 | 84 | ||
| 79 | void AudioPlayer::play(AudioPlayer::Sound sound) | 85 | void AudioPlayer::play(AudioPlayer::Sound sound) |
| 80 | { | 86 | { |
| 81 | #ifdef SERVER | 87 | if (!isWorking()) |
| 82 | return; | 88 | { |
| 83 | #endif // SERVER | ||
| 84 | if (!m_working) | ||
| 85 | emit finished_p(); | 89 | emit finished_p(); |
| 90 | return; | ||
| 91 | } | ||
| 86 | 92 | ||
| 87 | m_player->stop(); | 93 | m_player->stop(); |
| 88 | m_player->setCurrentSource(Phonon::MediaSource(m_sounds[sound])); | 94 | m_player->setCurrentSource(Phonon::MediaSource(m_sounds[sound])); |
| @@ -91,27 +97,29 @@ void AudioPlayer::play(AudioPlayer::Sound sound) | |||
| 91 | 97 | ||
| 92 | void AudioPlayer::clear() | 98 | void AudioPlayer::clear() |
| 93 | { | 99 | { |
| 94 | if (!m_working) | 100 | if (!isWorking()) |
| 95 | return; | 101 | return; |
| 96 | m_player->clear(); | 102 | m_player->clear(); |
| 97 | } | 103 | } |
| 98 | 104 | ||
| 99 | void AudioPlayer::enqueue(AudioPlayer::Sound sound) | 105 | void AudioPlayer::enqueue(AudioPlayer::Sound sound) |
| 100 | { | 106 | { |
| 101 | if (!m_working) | 107 | if (!isWorking()) |
| 102 | return; | 108 | return; |
| 103 | m_player->enqueue(Phonon::MediaSource(m_sounds[sound])); | 109 | m_player->enqueue(Phonon::MediaSource(m_sounds[sound])); |
| 104 | } | 110 | } |
| 105 | 111 | ||
| 106 | void AudioPlayer::clearQueue() const | 112 | void AudioPlayer::clearQueue() const |
| 107 | { | 113 | { |
| 108 | if (!m_working) | 114 | if (!isWorking()) |
| 109 | return; | 115 | return; |
| 110 | m_player->clearQueue(); | 116 | m_player->clearQueue(); |
| 111 | } | 117 | } |
| 112 | 118 | ||
| 113 | Phonon::State AudioPlayer::state() | 119 | Phonon::State AudioPlayer::state() |
| 114 | { | 120 | { |
| 121 | if (!isWorking()) | ||
| 122 | return Phonon::ErrorState; | ||
| 115 | return m_player->state(); | 123 | return m_player->state(); |
| 116 | } | 124 | } |
| 117 | 125 | ||
