Answer the question
In order to leave comments, you need to log in
How to properly play a wav file in qt?
I am writing a program that will play wav files. First experience with QT.
I read the header of the wav file byte by byte, and then I read the sound data in fragments into a QByteArray, which I then write to the QIODevice.
The problem is that instead of music, I only hear the first note of my file and the playback stops.
QAudioOutput * m_audioOutput;
QByteArray buffer;
QIODevice * m_output;
m_audioOutput = new QAudioOutput(m_fileFormat);
m_output=m_audioOutput->start();
buffer = wavFile.read(wavHeader.bytesPerSec);
m_output->write(buffer.data(), buffer.size());
QEventLoop loop;
QObject::connect(m_output, SIGNAL(bytesWritten(qint64)), &loop, SLOT(quit()));
loop.exec();
Answer the question
In order to leave comments, you need to log in
Other code would be nice, but at the very least it looks weird to interrupt the event loop. I understand correctly that after it the program ends?
If so, then everything is clear: you have written data to the OS mixer and queued it for playback, then send a signal that the data has been written and then close the application.
Of course, everything you have recorded is removed from the mixer
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question