diff options
Diffstat (limited to 'pacman-c++/audioplayer.cpp')
| -rw-r--r-- | pacman-c++/audioplayer.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/pacman-c++/audioplayer.cpp b/pacman-c++/audioplayer.cpp new file mode 100644 index 0000000..8620190 --- /dev/null +++ b/pacman-c++/audioplayer.cpp | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | #include "audioplayer.h" | ||
| 2 | #include <phonon/AudioOutput> | ||
| 3 | #include <phonon/MediaObject> | ||
| 4 | #include <QFile> | ||
| 5 | #include <QDebug> | ||
| 6 | |||
| 7 | // the universe's only audio player | ||
| 8 | AudioPlayer *AudioPlayer::m_instance = 0; | ||
| 9 | |||
| 10 | AudioPlayer::AudioPlayer() | ||
| 11 | { | ||
| 12 | m_player = new Phonon::MediaObject(this); | ||
| 13 | |||
| 14 | connect(m_player, SIGNAL(finished()), this, SLOT(finished_p())); | ||
| 15 | connect(m_player, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged_p(Phonon::State, Phonon::State))); | ||
| 16 | |||
| 17 | m_output = new Phonon::AudioOutput(Phonon::MusicCategory, this); | ||
| 18 | Phonon::createPath(m_player, m_output); | ||
| 19 | } | ||
| 20 | |||
| 21 | AudioPlayer *AudioPlayer::self() | ||
| 22 | { | ||
| 23 | if (!m_instance) | ||
| 24 | m_instance = new AudioPlayer(); | ||
| 25 | return m_instance; | ||
| 26 | } | ||
| 27 | |||
| 28 | void AudioPlayer::stop() | ||
| 29 | { | ||
| 30 | m_player->stop(); | ||
| 31 | } | ||
| 32 | |||
| 33 | void AudioPlayer::setMuted(bool mute) | ||
| 34 | { | ||
| 35 | m_output->setMuted(mute); | ||
| 36 | } | ||
| 37 | |||
| 38 | void AudioPlayer::playIntro() | ||
| 39 | { | ||
| 40 | m_player->stop(); | ||
| 41 | m_player->setCurrentSource(new QFile(":/sound/intro")); | ||
| 42 | m_player->play(); | ||
| 43 | } | ||
| 44 | |||
| 45 | void AudioPlayer::finished_p() | ||
| 46 | { | ||
| 47 | qDebug() << "finished"; | ||
| 48 | emit finished(); | ||
| 49 | } | ||
| 50 | |||
| 51 | void AudioPlayer::stateChanged_p(Phonon::State newstate, Phonon::State oldstate) | ||
| 52 | { | ||
| 53 | qDebug() << "old=" << oldstate << "new=" << newstate; | ||
| 54 | } | ||
| 55 | |||
