Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading + caching + playing audio at the same time

Is there a beautiful way to download an MP3 file via HTTP and cache it, playing it at the same time?

I tried to write downloaded bytes to a file and play that file using MediaPlayer. But when playing speed reaches downloading speed, playback stops. I don't think I'm thinking in a right direction. Writing into a file and reading it it at the same time seems to be quite strange, or am I wrong?

like image 853
Andrey Moiseev Avatar asked Feb 20 '23 23:02

Andrey Moiseev


1 Answers

But when playing speed reaches downloading speed, playback stops.

This is the key: you cannot play what you have not downloaded yet, no matter how you handle files, bytes etc. on the client side.

Most of applications that try to play "live" have buffer long enough to compensate for fluctuations of download speed. And if download speed is actually slower than playback speed (which is unusual for audio stream but possible) your goal may be not achievable at all - you may have to download whole song before playing it in order to ensure there will be no pauses in the playback.

like image 145
amoiseyev Avatar answered Feb 24 '23 17:02

amoiseyev