Problem in streaming ogg file

Hi All,

Hope you are doing well.

In my application I am downloading ogg file by using URL class and createInputStream() API of URL class. I am using a while loop in a thread to stream this downloading.
The problem I am facing is suppose I download 100K bytes at first time and then the other file in the while loop, then while playback I can play the first chunk of track very well but after the play finish the 100k of data then it started giving static output with original sound and even the play is bit in speed. I debugged into the OggReader but couldn’t any clue.

Please help me out!!!

Thanks in advance!


Sounds like it’s probably just a simple mistake, but impossible to tell from your description…

Hi Jules,

I will explain it again.
I have download thread to download the ogg format track from server, using URL class.
In run() method of thread I am downloading first 100k bytes then using a while loop to download the rest of the data.
Now when I start playback(still downloading is going on) I can able to play the 1st portion of the track which i download before while loop very well. And after that the track plays bit in speed and with the static sound.

Please let me know if this is still not clear to you.

Thanks for your time!!!

Do you buffer the downloaded contents till it reaches 100K, if you are please make a check whether you are writing the right contents to the files.

I understood the first time - you’ve obviously just messed-up your file writing loop, but how do you expect us to be able to tell you what you’ve done wrong in code that we’ve never seen?

Yes I am buffering the downloaded content, and I am able to play the same downloaded file outside my application with any other media player. So the contents are correct. Even If I load the same file next time in my application I can able to play.
The only problem is while streaming I am not able to play the downloading contents. I think this is again the same issue with the length of the file, because when we load a file using juce the file size will be fix it won’t change as the actual file is changed due to streaming.

Please let me know how can I change the static file size to dynamic one?

Can you post the code where you are buffering the downloaded contents and also the code where you write the downloaded contents to the file. It would be helpful in understanding the problem.

Ah, I see. Well, that’s really a limitation of juce’s ogg reader class - it doesn’t expect the file to change while it’s using it.

There might actually be a way to trick it into working, if you were to create a special file reader InputStream that avoided returning the size of the stream… No idea if that’d work!

Hi Jules,

Thanks for your suggestion!!!
I will try it, and let you know the result!


Hi Santo, did you ever figure out a solution to this? I’m working on something similar where I need to stream ogg files from the web. I’m having the same issue trying to play an ogg file while it is still downloading. It will play the beginning of the file perfectly, but since OggReader bases the file size on that first chunk of audio (i.e. whatever is already downloaded into the file when you create the reader) it stops playing when it reaches the end of that chunk even though more chunks have downloaded in the meantime.

I realize this thread is over 10years old but if anyone has any advice that would be much appreciated!