Issues with WWW resource loading

I am using the WWW class to load audio-clips at runtime as selected by the user. However, I am currently facing two issues. I am posting a code example here to explain.

    IEnumerator LoadSong(string trackpath)
	{		
		WWW checker = new WWW("file://"+trackpath);

		yield return checker;
		
		audClip = checker.GetAudioClip(true,true);
		
	}

This NEVER works. More specifically the line yield return checker; doesn’t. I have to replace that with while(!checker.isDone); to forcibly wait till the clip is loaded. What am I doing wrong here?

Secondly, some songs will never load too. After extensive testing I found out that almost 5 out of 200 songs don’t load. Also even if the audio isn’t loaded audClip doesn’t return a NULL value which suggests that something is being loaded, however

            Debug.Log("No of Samples : "+audClip.samples);
			Debug.Log ("Frequency : " + audClip.frequency);
			Debug.Log("No of channels : "+audClip.channels);
			Debug.Log("No of length : "+audClip.length);

all four values return 0. I believe this problem is related to yield not working properly.

Any help here would be much appreciated.

For the WWW problem:

It sounds like you are calling the function instead of starting a coroutine. Here’s the link to the docs, but in short:

//Do this
StartCoroutine(LoadSong());

//Instead of this
LoadSong();

For the songs not loading:

If some of the songs work, but other don’t, I don’t think it’s a problem with the WWW fetch. Maybe there is something different about the files themselves (size, format, etc). Just a guess.

~C