use qsoundeffect as it has ALSA support for WAV files, use qmediaplayer for other files

This commit is contained in:
Martin Rotter 2021-12-14 11:34:54 +01:00
parent 24db7c5371
commit 94585e5f97
2 changed files with 63 additions and 35 deletions

View file

@ -26,7 +26,7 @@
<url type="donation">https://github.com/sponsors/martinrotter</url>
<content_rating type="oars-1.1" />
<releases>
<release version="4.0.4" date="2021-12-10"/>
<release version="4.0.4" date="2021-12-14"/>
</releases>
<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute>

View file

@ -8,6 +8,7 @@
#if !defined(Q_OS_OS2)
#include <QMediaPlayer>
#include <QSoundEffect>
#if QT_VERSION_MAJOR == 6
#include <QAudioOutput>
@ -36,6 +37,32 @@ void Notification::setSoundPath(const QString& sound_path) {
void Notification::playSound(Application* app) const {
if (!m_soundPath.isEmpty()) {
#if !defined(Q_OS_OS2)
if (m_soundPath.endsWith(QSL(".wav"), Qt::CaseSensitivity::CaseInsensitive)) {
qDebugNN << LOGSEC_CORE << "Using QSoundEffect to play notification sound.";
QSoundEffect* play = new QSoundEffect(app);
QObject::connect(play, &QSoundEffect::playingChanged, play, [play]() {
if (!play->isPlaying()) {
play->deleteLater();
}
});
if (m_soundPath.startsWith(QSL(":"))) {
play->setSource(QUrl(QSL("qrc") + m_soundPath));
}
else {
play->setSource(QUrl::fromLocalFile(
QDir::toNativeSeparators(app->replaceDataUserDataFolderPlaceholder(m_soundPath))));
}
play->setVolume(m_volume);
play->play();
}
else {
qDebugNN << LOGSEC_CORE << "Using QMediaPlayer to play notification sound.";
QMediaPlayer* play = new QMediaPlayer(app);
#if QT_VERSION_MAJOR == 6
@ -80,6 +107,7 @@ void Notification::playSound(Application* app) const {
play->setVolume(m_volume);
play->play();
#endif
}
#endif
}
}