S
S
Smosia2014-03-11 04:16:01
Qt
Smosia, 2014-03-11 04:16:01

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();

It seems to me that I'm not working with the signal correctly. Tell me, what could be my mistake? Why instead of music only this one note? Thanks in advance.
ps. I can post the rest of the code if needed.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DancingOnWater, 2014-03-11
@Smosia

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

E
EXL, 2014-03-11
@EXL

Have you considered phonon?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question