PDA

View Full Version : Playing an mp3 while it is downloading



bittuthegr8
4th March 2011, 14:53
i want to download the mp3 to a cache folder and play it at the same time
maybe pause the playback just before a the end of the file and then play after a sufficient enough gap has been established (this would work so that the gap restriction is in effect from the start of playback giving initial buffer time)
also what does MediaSource::MediaSource(const QUrl) do when it comes to buffering

could someone give an example on how to do this

i found this post but the method seems a little crude
http://www.qtcentre.org/threads/38071-Playing-file-with-Phonon-while-stil-downloading-it.

wysota
6th March 2011, 08:33
You should be able to play from a custom QIODevice - this should work in your case if the device is sequential.

bittuthegr8
6th March 2011, 15:15
i dont understand what you mean maybe you could give a small example

wysota
6th March 2011, 16:11
Unfortunately there is no small example to give. You'd need to implement a subclass of QIODevice that would download the file from network (e.g. using QNetworkAccessManager) and feed it to Phonon at the same time saving it to disk.

bittuthegr8
7th March 2011, 01:26
Thanks for the reply
i just want to know what the custom class should do when the player runs out of buffer
should i implement a custom signal-slot to pause playback (or go into a buffering state).
is it possible to know when only a certain ammount of buffer is left (like 512Kb)

squidge
7th March 2011, 08:21
I'd imagine you would do the same as if the file was being retrieved from over the network (which is, in effect, what is happening)

As for buffering, you would know that yourself. You will know how much of the file has been read and how much you have received from the network. However, I wouldn't worry about it, if you run out of data theres not much you can do.

I'm not sure how well this kind of technique will work with MP3 files - typically you seek to the end of an MP3 to search for an ID3 tag before seeking back to the start to play the file. I don't know if Phonon does this, but if it does, maybe you would need to emulate this behavior (possibly with fake information, knowing the file type being retrieved of your I/O interface)

wysota
7th March 2011, 10:37
I'm not sure how well this kind of technique will work with MP3 files - typically you seek to the end of an MP3 to search for an ID3 tag before seeking back to the start to play the file. I don't know if Phonon does this, but if it does, maybe you would need to emulate this behavior (possibly with fake information, knowing the file type being retrieved of your I/O interface)
The IO device needs to be sequential for all this to work thus you can't seek in the stream. In a general case it's possible to play an mp3 stream so here it should work too.