Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Proper way playing oga files as sound effects
Forum Updated to NodeBB v4.3 + New Features

Proper way playing oga files as sound effects

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 239 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VahagnI
    wrote on last edited by
    #1

    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_;
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      The details of QSoundEffect explain that only uncompressed formats are supported, typically wav files.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved