PDA

View Full Version : Play oga files with QSoundEffect



vahagn
17th February 2020, 13:38
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

Also,

qDebug() << QSoundEffect::supportedMimeTypes();
outputs


("audio/x-wav", "audio/vnd.wave")

A less important question. Is the way I am using the QSoundEffect class a proper way (see the code below)?



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_;

};