PDA

View Full Version : problem with save mp3 with QNetworkReply



azazaz
15th June 2016, 16:35
i want safe mp3 stream to file

void Main::reply_readyReadSlot()
{
//buff its QBuffer;
buff.write(reply->readLine());

}

always destination file lost ~5% of headers, you can look this file this (http://rgho.st/8cKFyjGd4).
maybe need writing buffer in other place?

anda_skoa
15th June 2016, 17:25
readLine(), reads, as it says, a line. So until an "end of line" character.
If your data is mp3 data, then it is not text, so you shouldn't be treating it like text.

If your want to read all data that is available at this point, use readAll()

Cheers,
_

azazaz
15th June 2016, 23:47
readLine(), reads, as it says, a line. So until an "end of line" character.
If your data is mp3 data, then it is not text, so you shouldn't be treating it like text.

If your want to read all data that is available at this point, use readAll()

Cheers,
_


char buffer[2048];
qint64 size = reply->read(buffer, sizeof(buffer));
buf.write(buffer, size);



QByteArray qa;
qa=reply->readAll();
buf.write(qa.data(),qa.size() );


QByteArray qa;
qa = reply->read(16 * 1024);
buf.write(qa.data(),qa.size());
mp3file.writeRawData(qa.data() ,qa.size());

void MainWindow::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
QByteArray qa;
qa = reply->read(bytesReceived);
buf.write(qa.data(),qa.size());
mp3file.writeRawData(qa.data() ,qa.size());

}

no difference,always mp3 data broken
but writing mp3 from static files(from url) goes well!

anda_skoa
16th June 2016, 10:42
Since the device you are reading from seems to be a QNetworkReply, are you sure the data is just the MP3 data, not including HTML, etc?

Cheers,
_