- Home /
Streaming Music from Disk
I'm trying to allow my users to place their own music into a folder (in OGG format) in standalone builds of my game.
I have playback working by using the 'WWW' class with a 'file://' URL - this gives me an AudioClip with 'stream' set to true.
However, after around about 30-40 seconds of playback I start getting errors like this - 'WWW: out of memory'.
I'm assuming this is because the WWW class is trying to extract the entire OGG track uncompressed into memory?
Is there any way that I can...
a) Force the system to load the file as COMPRESSED rather than UNCOMPRESSED (ie. the same way as checking 'Compressed In Memory' if I had built the sound file into my Unity project?
b) Failing that, increase the buffer size for the WWW class to allow a larger file to be downloaded?
c) Clear out the portion of the AudioClip already downloaded and played, to create more memory for incoming data?
The only other option I have is that I can manually decode the data directly with file IO and a library such as Mp3Sharp, managing the playing buffer myself via the PCMReaderCallback functions. However, I was hoping that Unity would have some out-of-the-box support for this.
Answer by Marrt · Dec 10, 2012 at 02:00 PM
after 30-40s already? strange, maybe you already have a large amount of audioData loaded in your memory as you start streaming... How are the other sound effects loaded?
also, im not sure if Unity clears the already loaded Tracks if they aren't needed anymore: I am not completely sure this works, but please try this: downloader = new WWW(url);//your Download downloader.Dispose();//get rid of the Data in memory, at least i think it does that :D
Unfortunately there are almost no other samples loaded, and just in case I tried running it without those loaded.
The samples that are there are only 1-2s in duration, used as audio confirmation of user actions.
maybe another thing is dumping in your memory, however, it would seem inlikely that the small audio download would just be enough to reach the memory limit then... try to watch the task manager of your Operating System as you start the Unity WWW-download, watch its $$anonymous$$emory usage, then try running the same build without the download
You could post some of your code too...
Your answer
Follow this Question
Related Questions
Stream music in Unity mobile 0 Answers
Streaming music 3 Answers
Building a browserbased venue with streaming audio 0 Answers
How do I stream audio from disk? 0 Answers
Unintended audio gaps 1 Answer