Linux Sound Woes



  • Hi, I'm new to using Qt and I've been having a lot of success in getting it to work and do what I want.... then I decided to try adding sounds to my program and now a day and a half later I'm still unable to load and play a simple wav or mp3 file.

    I've tried using qsound (Error decoding source) and I've tried phonon (Qt4.8) and the media player (Qt5.5) and I've waded through a world of backend issues and missing services and failure to load the installed streamer (yes I have the dev package installed too). Short of rebuilding everything from source (which seems like it shouldn't have to come to that, why have a linux installer if critical features like sound are broken as a result of using it). Regardless of following every forum post and hint I could find online to try and solve this I am still unable to play any sounds what so ever.

    I find this massively disappointing. Why shouldn't sound work 'out of the box'. I mean comon... pygame can play sounds right off... and a platform as major as linux should have support for playing sound. So now I've come to the point of frustration where I'm actually taking the time to write this out. So my question: "What exactly do I have to do to get a simple .wav or .mp3 file to play in either a Qt 4 or 5 application on linux?". For how many people are seem to be having this exact same issue there doesn't seem to be much in the way of a solution since there's a lot of people asking, very few answers and a lot of "fixes" that fix nothing.

    SO FRUSTRATED!


  • Moderators

    Hi, welcome to the forum.

    Maybe a silly question, but are you sure the path to the file is correct? One of the reasons "error decoding sound" message shows up is when the source file is not found.

    Anyway, I'm not a Linux guy, but I have a Ubuntu VM so I just tried this (Qt 5.5.1 from the online installer):

    #include <QApplication>
    #include <QPushButton>
    #include <QSound>
    
    int main(int argc, char *argv[]) {
        QApplication a(argc, argv);
    
        QPushButton button;
        button.show();
    
        QObject::connect(&button, &QPushButton::clicked, []{
            QSound::play("./test.wav");
        });
    
        return a.exec();
    }
    

    I didn't install anything extra, No additional setup. Just compiled and it run and played the sound "out of the box".


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.