Hi,
I am developing an application with sound effects and I want to use the QSoundEffect class as it is intended. However, the "native" sound effects of Ubuntu at, say, "/usr/share/sounds/freedesktop/" have oga format. Is there a way to play them with QSoundEffect? When I set the source of a QSoundEffect instance to one of these files the app prints
QSoundEffect(pulseaudio): Error decoding source
QSoundEffect(pulseaudio): Error decoding source
To copy to clipboard, switch view to plain text mode
Also,
qDebug() << QSoundEffect::supportedMimeTypes();
qDebug() << QSoundEffect::supportedMimeTypes();
To copy to clipboard, switch view to plain text mode
outputs
("audio/x-wav", "audio/vnd.wave")
("audio/x-wav", "audio/vnd.wave")
To copy to clipboard, switch view to plain text mode
A less important question. Is the way I am using the QSoundEffect class a proper way (see the code below)?
public:
MyClass(){
sound_effects_["ok"] = new QSoundEffect(this);
sound_effects_
["ok"]->setSource
(QUrl::fromLocalFile("/usr/share/sounds/freedesktop/some-file.oga")));
sound_effects_["error"] = new QSoundEffect(this);
sound_effects_
["error"]->setSource
(QUrl::fromLocalFile("/usr/share/sounds/freedesktop/other-file.oga")));
// ...
connect(this, &MyClass::PlaySound, this, &MyClass::Play);
//....
}
void SomeFunctionInBackgroundThread(){
//
if(success)
emit PlaySound("ok");
else
emit PlaySound("error");
}
singals:
void PlaySound
(const QString & name
);
private slots:
sound_effects_[name]->play();
}
private:
QMap<QString, QSoundEffect *> sound_effects_;
};
class MyClass : public QDialog{
public:
MyClass(){
sound_effects_["ok"] = new QSoundEffect(this);
sound_effects_["ok"]->setSource(QUrl::fromLocalFile("/usr/share/sounds/freedesktop/some-file.oga")));
sound_effects_["error"] = new QSoundEffect(this);
sound_effects_["error"]->setSource(QUrl::fromLocalFile("/usr/share/sounds/freedesktop/other-file.oga")));
// ...
connect(this, &MyClass::PlaySound, this, &MyClass::Play);
//....
}
void SomeFunctionInBackgroundThread(){
//
if(success)
emit PlaySound("ok");
else
emit PlaySound("error");
}
singals:
void PlaySound(const QString & name);
private slots:
void Play(const QString & name){
sound_effects_[name]->play();
}
private:
QMap<QString, QSoundEffect *> sound_effects_;
};
To copy to clipboard, switch view to plain text mode
Bookmarks