I'm about to load an online content (say an audio file). If I just open a connection to the remote file (for example by use of new URL().openStream()
) and pass the remote InputStream
to the audio player, it reads gradually from the network. If audio player library do not ask InputStream
for more data, it reads nothing from the network, and then when the library claims more, it reads again.
My problem is that I want to start caching the next online audio file, as soon as the loading process of the first one is finished. Using a normal InputStream
, reading is complete as the audio playing is done, which is not good since I want it read faster if network bandwidth allows, so that caching the next audio file. My audio files are smaller that 3mb so can be safely cached to the memory. I only prefetch a single file, so no problem with memory leak.
Is there any type of caching InputStream
, which also allows concurrent read? I can then run a thread and cache the audio faster than the audio player consumes the data.