I’m trying to stream a local audio file using the WWW class. The problem is that it blocks unity until it is loaded, in my case the blocking last about 5 seconds:
public IEnumerator audioThread()
{
while(true)
{
if (startStreaming_ )
{
WWW location = new WWW("file://audio1.ogg");
while (!location.isDone)
{
print("before wait..");
yield return new WaitForSeconds(0.2f);
print("after wait..");
}
audioSource_.clip = location.oggVorbis;
audioSource_.loop = true;
startStreaming_ = false;
}
// Wait 100 msec
yield return new WaitForSeconds(0.1f);
}
}
void Start () {
StartCoroutine(audioThread());
startStreaming_ = true;
}
I would expect that the audio would “load” in the “background”. It does not and blocks…
What is also strange is that it blocks after having called:
yield return new WaitForSeconds(0.2f);
So “before wait…” is printed,
then everything blocks for 5 seconds,
then “after wait…” is printed and the audio is finaly played…