Efog
Efog

Reputation: 1179

Play wav file in linux

I know that this question is a duplicate. But in other questions, people advise Phonon which is not available in Qt 5+ (I'm using 5.4).

I also tried to use QAudioOutput:

    QFile inputFile;
    inputFile.setFileName("/home/efog/G6_Build/sound.wav");
    inputFile.open(QIODevice::ReadOnly);

    QAudioFormat format;
    format.setSampleRate(44100);
    format.setChannelCount(2);
    format.setSampleSize(16);
    format.setCodec("audio/wav");

    QAudioOutput *audio = new QAudioOutput( format, 0);
    audio->start(&inputFile);

But it is not working, same as QSound:

    QSound::play("/home/efog/G6_Build/sound.wav");

NAS and GStreamer are installed. So, how can I play wav files?

Upvotes: 3

Views: 2740

Answers (1)

user4516901
user4516901

Reputation:

Sometimes QSound takes some time to play when it first loads the file. Try creating a QSound object with the file, and playing it afterwards, and maybe give it a little time.

QSound *sound = new QSound("/home/efog/G6_Build/sound.wav");
sound->play();

And are you sure, your wav file is really a wav file? I've seen audio files with wav extension, but actually they were mp3 files. Maybe try with another audio file first.

Upvotes: 2

Related Questions