use qsoundeffect as it has ALSA support for WAV files, use qmediaplayer for other files
This commit is contained in:
parent
24db7c5371
commit
94585e5f97
2 changed files with 63 additions and 35 deletions
|
@ -26,7 +26,7 @@
|
||||||
<url type="donation">https://github.com/sponsors/martinrotter</url>
|
<url type="donation">https://github.com/sponsors/martinrotter</url>
|
||||||
<content_rating type="oars-1.1" />
|
<content_rating type="oars-1.1" />
|
||||||
<releases>
|
<releases>
|
||||||
<release version="4.0.4" date="2021-12-10"/>
|
<release version="4.0.4" date="2021-12-14"/>
|
||||||
</releases>
|
</releases>
|
||||||
<content_rating type="oars-1.0">
|
<content_rating type="oars-1.0">
|
||||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#if !defined(Q_OS_OS2)
|
#if !defined(Q_OS_OS2)
|
||||||
#include <QMediaPlayer>
|
#include <QMediaPlayer>
|
||||||
|
#include <QSoundEffect>
|
||||||
|
|
||||||
#if QT_VERSION_MAJOR == 6
|
#if QT_VERSION_MAJOR == 6
|
||||||
#include <QAudioOutput>
|
#include <QAudioOutput>
|
||||||
|
@ -36,6 +37,32 @@ void Notification::setSoundPath(const QString& sound_path) {
|
||||||
void Notification::playSound(Application* app) const {
|
void Notification::playSound(Application* app) const {
|
||||||
if (!m_soundPath.isEmpty()) {
|
if (!m_soundPath.isEmpty()) {
|
||||||
#if !defined(Q_OS_OS2)
|
#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);
|
QMediaPlayer* play = new QMediaPlayer(app);
|
||||||
|
|
||||||
#if QT_VERSION_MAJOR == 6
|
#if QT_VERSION_MAJOR == 6
|
||||||
|
@ -80,6 +107,7 @@ void Notification::playSound(Application* app) const {
|
||||||
play->setVolume(m_volume);
|
play->setVolume(m_volume);
|
||||||
play->play();
|
play->play();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue