Skip to content

Commit

Permalink
add: use wav files to play sound effects
Browse files Browse the repository at this point in the history
Change-Id: I4baa6db80ccd109826a6135b666df4e8ee281449
  • Loading branch information
listenerri committed Jun 21, 2018
1 parent 4a1487c commit dbd7077
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/util/ddesktopservices_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QFile>
#include <QMediaPlayer>
#include <QGSettings/QGSettings>
#include <QSound>

DWIDGET_BEGIN_NAMESPACE

Expand Down Expand Up @@ -80,13 +81,19 @@ static QString soundEffectFilePath(const QString &name)
{
// TODO: super simple version of sound theme file search shema :)
// will need to be replaced by more advanced approch like libcanberra.
const QString temp = QString("/usr/share/sounds/deepin/stereo/%1.ogg").arg(name);
QString temp = QString("/usr/share/sounds/deepin/stereo/%1").arg(name);

if (QFile::exists(temp)) {
return temp;
} else {
return QString();
const QString tempWav = temp + ".wav";
if (QFile::exists(tempWav)) {
return tempWav;
}

const QString tempOgg = temp + ".ogg";
if (QFile::exists(tempOgg)) {
return tempOgg;
}

return QString();
}

static bool systemSoundEffectEnabled(const QString &name)
Expand Down Expand Up @@ -215,9 +222,13 @@ bool DDesktopServices::playSystemSoundEffect(const QString &name)
return false;
}

QMediaPlayer *player = soundEffectPlayer();
player->setMedia(QUrl::fromLocalFile(path));
player->play();
if (path.endsWith("wav")) {
QSound::play(path);
} else {
QMediaPlayer *player = soundEffectPlayer();
player->setMedia(QUrl::fromLocalFile(path));
player->play();
}

return true;
}
Expand Down

0 comments on commit dbd7077

Please sign in to comment.