PDA

View Full Version : Read audio file while i downloading it



johann74270
28th June 2014, 15:25
Hello all the world!
I would like to set up an application which would be able to read musics cuts out of small piece.
Admittedly, while I download the parts in the order of a file, I wish to start to read the first pieces I wish to read these musics with the Phonon module included in my version of QT

Thanks for reading ! if you have idea, a solution !

Here what I have to begin has to make:

Phonon::MediaObject* music;

void MainWindow::on_pushButton_clicked()
{
QFile* MonFichier = new QFile(QString("C:/SPLIT/ORIGINAL.wav.001"));
MonFichier->open(QIODevice::ReadOnly);

QByteArray* MonArray = new QByteArray();
MonArray->resize(40000000);
MonArray->replace(0,MonFichier->readAll().length(),MonFichier->readAll());
MonArray->resize(40000000);

QBuffer* MonBuffer = new QBuffer(MonArray);
MonBuffer->open(QIODevice::ReadWrite);
}

void MainWindow::on_pushButton_2_clicked()
{
qint64 Temp = music->currentTime();

music->seek(Temp);
}

anda_skoa
29th June 2014, 11:56
QFile::readAll() returs the file's content and moves the "file pointer", i.e. positions the seek position at the end of the file.
So your two subsequent readAll() calls have different results.

Something like this would probably be better


// on the stack unless you really need the file to remain open after the method ends.
QFile MonFichier(QString("C:/SPLIT/ORIGINAL.wav.001"));
MonFichier.open(QIODevice::ReadOnly);

QByteArray MonArray = MonFichier.readlAll();
MonArray->resize(40000000);

QBuffer* MonBuffer = new QBuffer(this);
MonBUffer->setData(MonArray);
MonBuffer->open(QIODevice::ReadWrite);
}


If you are downloading the file using some Qt I/O classes, you might be able to skip writing to a file, i.e. write the recieved data into the buffer object directly

Cheers,
_