Commit f78c01fa authored by Fabio Bas's avatar Fabio Bas
Browse files

Avoid multiple sounds playing at the same time

parent 85aa866e
......@@ -33,7 +33,7 @@
#define TEST_SOUND_FILENAME "player_join"
SoundEngine::SoundEngine(QObject *parent)
: QObject(parent), enabled(false)
: QObject(parent), engine(0)
{
ensureThemeDirectoryExists();
connect(settingsCache, SIGNAL(soundThemeChanged()), this, SLOT(themeChangedSlot()));
......@@ -43,6 +43,15 @@ SoundEngine::SoundEngine(QObject *parent)
themeChangedSlot();
}
SoundEngine::~SoundEngine()
{
if(engine)
{
delete engine;
engine = 0;
}
}
void SoundEngine::soundEnabledChanged()
{
if (settingsCache->getSoundEnabled()) {
......@@ -57,7 +66,7 @@ void SoundEngine::soundEnabledChanged()
}
#else
qDebug("SoundEngine: enabling sound");
enabled = true;
enabled = true;
#endif
} else {
qDebug("SoundEngine: disabling sound");
......@@ -76,7 +85,19 @@ void SoundEngine::playSound(QString fileName)
if(!fi.exists())
return;
QSound::play(fi.absoluteFilePath());
if(engine)
{
if(engine->isFinished())
{
engine->stop();
delete engine;
} else {
return;
}
}
engine = new QSound(fi.absoluteFilePath());
engine->play();
}
void SoundEngine::testSound()
......
......@@ -6,16 +6,20 @@
#include <QDir>
#include <QString>
class QSound;
typedef QMap<QString, QString> QStringMap;
class SoundEngine : public QObject {
Q_OBJECT
public:
SoundEngine(QObject *parent = 0);
~SoundEngine();
void playSound(QString fileName);
QStringMap &getAvailableThemes();
private:
bool enabled;
QSound * engine;
QStringMap availableThemes;
protected:
void ensureThemeDirectoryExists();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment