PDA

View Full Version : save music after played from url to local



solook
23rd June 2011, 11:40
hi

i use this code to play music from Internet



Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
Phonon::createPath(mediaObject, audioOutput);
Phonon::MediaSource source("http://mysite.com/001001.mp3");
mediaObject->setCurrentSource(source);
mediaObject->play();


how can i save 001001.mp3 in local after played..?

Santosh Reddy
25th June 2011, 11:15
find out a way to know the end of music playing, and then call download() as below, or just call download() after play()

I am not sure of this but, can try

download()
{
QNetworkReply * reply = QNetworkAccessManager::get ("http://mysite.com/001001.mp3");
connect(reply, SIGNAL(readyRead()), this, SLOT(saveToFile());
}

saveToFile()
{
QByteArray data = reply->readAll();
QFile file("001001.mp3");
if (!file.open(QIODevice::WriteOnly))
return;
file.write(data);
file.close();
reply->deleteLater();
}