Use QMediaPlayer instead of QSoundeffect
...but it STILL dowsn't respect ringtone volume...
This commit is contained in:
parent
284c46196e
commit
07c463b238
2 changed files with 10 additions and 9 deletions
|
@ -22,7 +22,9 @@ MyNotification::MyNotification(QObject* parent) : QObject(parent)
|
||||||
notification.setAppName("Battery Buddy");
|
notification.setAppName("Battery Buddy");
|
||||||
notification.setAppIcon("harbour-batterybuddy");
|
notification.setAppIcon("harbour-batterybuddy");
|
||||||
playSound = false;
|
playSound = false;
|
||||||
connect(&sound, SIGNAL(loadedChanged()), &sound, SLOT(play()));
|
sound.setAudioRole(QAudio::NotificationRole);
|
||||||
|
connect(&sound, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
|
||||||
|
this, SLOT(soundLoadedChanged(QMediaPlayer::MediaStatus)));
|
||||||
}
|
}
|
||||||
|
|
||||||
MyNotification::~MyNotification()
|
MyNotification::~MyNotification()
|
||||||
|
@ -36,9 +38,9 @@ void MyNotification::send(QString title, QString body, QString soundFile)
|
||||||
body = body.replace("\"", "\\\"");
|
body = body.replace("\"", "\\\"");
|
||||||
|
|
||||||
playSound = true;
|
playSound = true;
|
||||||
if(sound.source() != QUrl::fromLocalFile(soundFile)) {
|
if(sound.media() != QUrl::fromLocalFile(soundFile)) {
|
||||||
// Signalled to play()
|
// Signalled to play()
|
||||||
sound.setSource(QUrl::fromLocalFile(soundFile));
|
sound.setMedia(QUrl::fromLocalFile(soundFile));
|
||||||
}
|
}
|
||||||
else if (playSound){
|
else if (playSound){
|
||||||
// Must manually trigger play()
|
// Must manually trigger play()
|
||||||
|
@ -61,8 +63,8 @@ void MyNotification::close()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyNotification::soundLoadedChanged() {
|
void MyNotification::soundLoadedChanged(QMediaPlayer::MediaStatus newStatus) {
|
||||||
if(playSound && sound.status() == QSoundEffect::Ready) {
|
if(playSound && newStatus == QMediaPlayer::LoadedMedia) {
|
||||||
sound.play();
|
sound.play();
|
||||||
playSound = false;
|
playSound = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,8 @@
|
||||||
#define MYNOTIFICATION_H
|
#define MYNOTIFICATION_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QProcess>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QSoundEffect>
|
#include <QMediaPlayer>
|
||||||
#include <nemonotifications-qt5/notification.h>
|
#include <nemonotifications-qt5/notification.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
@ -40,11 +39,11 @@ public slots:
|
||||||
private:
|
private:
|
||||||
QString noteID = "1";
|
QString noteID = "1";
|
||||||
Notification notification;
|
Notification notification;
|
||||||
QSoundEffect sound;
|
QMediaPlayer sound;
|
||||||
bool playSound;
|
bool playSound;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void soundLoadedChanged();
|
void soundLoadedChanged(QMediaPlayer::MediaStatus newStatus);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MYNOTIFICATION_H
|
#endif // MYNOTIFICATION_H
|
||||||
|
|
Loading…
Reference in a new issue