summaryrefslogtreecommitdiffstats
path: root/pacman-c++/audioplayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pacman-c++/audioplayer.cpp')
-rw-r--r--pacman-c++/audioplayer.cpp55
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
8AudioPlayer *AudioPlayer::m_instance = 0;
9
10AudioPlayer::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
21AudioPlayer *AudioPlayer::self()
22{
23 if (!m_instance)
24 m_instance = new AudioPlayer();
25 return m_instance;
26}
27
28void AudioPlayer::stop()
29{
30 m_player->stop();
31}
32
33void AudioPlayer::setMuted(bool mute)
34{
35 m_output->setMuted(mute);
36}
37
38void AudioPlayer::playIntro()
39{
40 m_player->stop();
41 m_player->setCurrentSource(new QFile(":/sound/intro"));
42 m_player->play();
43}
44
45void AudioPlayer::finished_p()
46{
47 qDebug() << "finished";
48 emit finished();
49}
50
51void AudioPlayer::stateChanged_p(Phonon::State newstate, Phonon::State oldstate)
52{
53 qDebug() << "old=" << oldstate << "new=" << newstate;
54}
55