I am pulling in OGG music files via WWW, and have noticed that each time it switches to a new track, there is a really nasty performance hiccup. I’m assuming the problem is that Unity is attempting to “decompress on load” this entire file, right then and there? So I’d like to change that to either “compress in memory” or “stream from disc”, I believe…feel free to tell me if I’m wrong on any of this Otherwise, I can’t seem to find how to set this via script, only editor classes, which I assume won’t work, and would really appreciate help figuring this one out.
Currently, my code goes thusly:
function Start()
{
//Begin pulling in music
GetMusic();
//--
}
function GetMusic()
{
var url : String;
var www = new WWW(url);
//print("Getting Music:");
while(musicTracks.length < musicLinks.length)
{
url = musicLinks[musicTracks.length];
//print("url: "+musicLinks[musicTracks.length]);
www = new WWW(url);
var tempClip : AudioClip = www.GetAudioClip(false, false); //non-3d, non-streaming;
//print("downloading...");
yield www;
//print("done!");
musicTracks.Add(tempClip);
//print("got "+musicTracks.length+" of "+musicLinks.length+" total tracks");
if(audio.clip == starterLoop)
{
//print("Switching from starter loop to real music!");
audio.loop = false;
audio.clip = musicTracks[0];
audio.Play();
}
}
}
function NextMusicTrack()
{
//print("Checking the stacks...");
if(currentTrackIndex == musicTracks.length-1)
{
//print("Last track reached, going back to zero!");
audio.clip = musicTracks[0];
audio.Play();
}
else
{
//print("We've got more music, on to the next!");
currentTrackIndex++;
audio.clip = musicTracks[currentTrackIndex];
audio.Play();
}
}
One point, I’m not using stream because it just doesn’t seem to work, and research here on the forums seemed to show that I simply can’t- I’ll try to find the threads I was reading on that. However, if anyone can point me toward a way to get streaming working properly, that would be great!
More importantly, the current method is working fine, other than the performance hit I’m hoping to solve here, via “compress in memory”/etc.
Any help much appreciated, thanks!