Proper way playing oga files as sound effects
Unsolved
General and Desktop
-
I am developing a GUI application under Ubuntu Linux with Qt5.
I want to use sounds from "/usr/share/sounds/freedesktop/" as sound effects, which contains .oga files. However, the QSoundEffect class seems to understand only .wav files.qDebug() << QSoundEffect::supportedMimeTypes();
outputs("audio/x-wav", "audio/vnd.wave")
and the application prints
QSoundEffect(pulseaudio): Error decoding source
at initialization.
Is there a way to play these files?I use the QSoundEffect as in the code snippet below. Is this the proper way to use the class?
Is using QMediaPlayer instead of QSoundEffect an overkill?class MyClass: public QDialog { public: MyClass(QObject * parent = nullptr): QDialog(parent) { QSoundEffect * ok = new QSoundEffect(this); ok->setSource("/path/to/file.oga"); sound_effects_["ok"] = ok; /*Initialize other effects*/ connect(this, &MyClass::PlaySound, this, &MyClass::Play); } void AFunctionFromADiffernetThread(){ // Do other things if(success) emit PlaySound("ok"); } signals: void PlaySound(const QString & name); private slots: void Play(const QString & name){ sound_effects_[name]->play(); } private: QMap<QString, QSoundEffect *> sound_effects_; }
-
Hi and welcome to devnet,
The details of QSoundEffect explain that only uncompressed formats are supported, typically wav files.