blob: bea7fb8b86b6e0243f10e46e0b8ba5333d04209c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#ifndef AUDIO_H
#define AUDIO_H
#include <QObject>
#include <QList>
#include <QFile>
#include <QThread>
#include <phonon/MediaObject>
namespace Phonon
{
class AudioOutput;
}
namespace Sound
{
enum Type
{
Intro = 0,
WakaWaka,
EatingCherry,
Die
};
};
class AudioPlayer
: public Phonon::MediaObject
{
Q_OBJECT
friend class AudioManager;
private:
class Sleeper
: public QThread
{
public:
static void sleep(unsigned long secs);
static void msleep(unsigned long msecs);
static void usleep(unsigned long usecs);
};
public:
AudioPlayer(QObject *parent = 0);
bool isWorking() const;
void setMuted(bool mute = true);
bool isMuted() const;
void setLoop(QFile *sound);
void setLoop(Sound::Type sound);
private:
void test(QFile *testsound);
public slots:
void loopEnqueue();
private slots:
void testFinished();
void stateChanged_ex(Phonon::State newstate, Phonon::State oldstate);
private:
bool m_working;
QFile *m_loopsound;
Phonon::AudioOutput *m_output;
};
class AudioManager
: public QObject
{
Q_OBJECT
friend class AudioPlayer;
public:
AudioManager();
static AudioManager *self();
bool isWorking() const;
void setMuted(bool mute = true);
bool isMuted() const;
void pause();
void stop();
void clear();
void clearQueue() const;
AudioPlayer *audioPlayer();
void play(Sound::Type sound);
void enqueue(Sound::Type sound);
void registerAudioPlayer(AudioPlayer *player);
void unregisterAudioPlayer(AudioPlayer *player);
signals:
void mutedChanged(bool muted);
private slots:
void unregisterAudioPlayer_helper(QObject *player);
private:
void preload();
QFile *sound(Sound::Type sound);
private:
bool m_muted;
static bool m_working;
static AudioManager *m_instance;
QList<QFile *> m_sounds;
QList<AudioPlayer *> m_players;
};
#endif // AUDIOPLAYER_H
|