-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisoundplayer.cpp
91 lines (71 loc) · 1.81 KB
/
isoundplayer.cpp
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
#include <QtCore>
#include <QDebug>
#include "isoundplayer.h"
#include "jnisoundeffect.h"
#include "qtsoundeffect.h"
ISoundPlayer::ISoundPlayer(QObject *parent)
: QObject(parent)
{
#ifdef UNDER_ANDROID
player = new JNISoundEffect();
#else
player = new QtSoundEffect();
#endif
}
ISoundPlayer::~ISoundPlayer()
{
}
void ISoundPlayer::move(QThread *to)
{
thread = to;
player->moveToThread(to);
connect(player, SIGNAL(playingChanged()), SLOT(playingChanged()),
Qt::QueuedConnection);
connect(this, SIGNAL(playSoundSignal(QString)),
player, SLOT(playSound(QString)), Qt::QueuedConnection);
}
void ISoundPlayer::flushQueue()
{
urisLock.lock();
if (uris.empty()) {
qDebug() << "empty sound list";
urisLock.unlock();
return;
}
qDebug() << "flushQueue player state" << player->isPlaying();
if (player->isPlaying()) {
urisLock.unlock();
return;
}
QUrl uri = QUrl(uris.at(0));
uris.removeFirst();
urisLock.unlock();
qDebug() << "flushQueue setMedia " << uri;
emit playSoundSignal(uri.toString());
}
void ISoundPlayer::playResourceSound(QString url)
{
// :/Resources/...
qDebug() << "playing resource sound " << url;
urisLock.lock();
uris.append("qrc" + url);
urisLock.unlock();
flushQueue();
}
void ISoundPlayer::playFileSystemSound(QString filename)
{
qDebug() << "playing filesystem sound " << filename;
urisLock.lock();
uris.append(QUrl::fromLocalFile(filename).toString());
urisLock.unlock();
flushQueue();
}
void ISoundPlayer::playingChanged()
{
qDebug() << "player status " << player->isPlaying();
if (!player->isPlaying()) {
flushQueue();
} else if (!uris.empty()){
QTimer::singleShot(100, this, SLOT(playingChanged()));
}
}