I'm having an issue playing a simple 'wav' file using QAudioOutput. Previously I used the QSound::PlaySound() to play the same wav and it worked fine, however I wanted a bit more control (mainly stop, pause, resume). However when I play the sound (any wav file) using QAudioOutput I get a 'pop' noise at the start of every sound. This did not occur with the QSound::PlaySound().
I've tried tweaking the QAudioFormat, but no luck there. I did basically just copy the code from the QAudioOutput help documents, with the exception that I determine the QAudioFormat by the WAV file's header. Note that I've also tested setting the QAudioFormat manually so I'm fairly confident the error is not there.
So basically when I want to play my wav file, I create a new SoundPlayer object, passing it the filename as a QString. The sound is played once the object is constructed.
SoundPlayer Constructor
{
this->inputFile.setFileName(fileName);
QAudioFormat format = getWaveFormat(fileName);
format.setCodec("audio/pcm");
this->audio = new QAudioOutput(format, this);
connect(audio, SIGNAL(stateChanged(QAudio::State)), SLOT(finishedPlaying(QAudio::State)));
//play the sound file 'inputFile'
audio->start(&inputFile);
}
SoundPlayer::SoundPlayer(QString fileName, QWidget *parent) :
QWidget(parent)
{
this->inputFile.setFileName(fileName);
this->inputFile.open(QIODevice::ReadOnly);
QAudioFormat format = getWaveFormat(fileName);
format.setCodec("audio/pcm");
this->audio = new QAudioOutput(format, this);
connect(audio, SIGNAL(stateChanged(QAudio::State)), SLOT(finishedPlaying(QAudio::State)));
//play the sound file 'inputFile'
audio->start(&inputFile);
}
To copy to clipboard, switch view to plain text mode
Bookmarks