Unable to get audio streaming from disc working correctly

I’ve been unable to get unity to stream my audio assets from disc. I believe this has to do with me loading audio clips into my scene with Resources.Load. Using the Profiler I find that the unity AudioManager uses a very large amount of RAM. Much more than the size of the actual size of the audio files I am using.

I decided to use the www. class to stream my larger audio files but have had no luck even getting a simple test version to work.
My implementation follows.

using UnityEngine;
using System.Collections;

public class AudioTest : MonoBehaviour {

	// Use this for initialization
	private AudioSource mTestClip;
	
	void Start () 
	{
		mTestClip =GetComponent<AudioSource>();
		StartCoroutine(PlayTestSound());
	}
	
	public IEnumerator PlayTestSound()
	{
	
		string filePath = Application.streamingAssetsPath + "/Audio/"+ "Male_Footsteps_01.ogg";
			
		WWW www = new WWW ( filePath );

       	        if ( www.error != null )
			Debug.Log ( www.error );
		
		yield return www;
			
		Debug.Log (filePath +"  sound download complete");
			
		mTestClip.clip = 	www.GetAudioClip ( false, true ,AudioType.OGGVORBIS);
        
		while (!mTestClip.clip.isReadyToPlay)
		{	
			Debug.Log ("Not playing");
			yield return www;
		}	
		
		mTestClip.Play();
		
	}
}

When I run this after a short period of around a second the statement “filePath +” sound download complete" is printed.

Then “Not playing” is repeatedly printed as mTestClip.clip.isReadyToPlay is never true.

I have also tried the above code with out the second while loop, just trying to play the clip with out checking if it is ready. This doesn’t work either.

If anybody has any advice regarding this or streaming large audio files in general (when using Resources.Load to bring audioclips into the scene dynamically) it would be much appreciated

I have the exact same problem… using 4.3.3f1:

Here’s my code

… Calling routine …

// Get clip
string strURL = AssetManager.GetAssetPath(strName);
string strFileProtocolAffix = “file://”;
strURL = strFileProtocolAffix + strURL;
Logger.LogInfo(LogGroups.Audio, "Streaming Audio path (getting www): " + strURL);

StartCoroutine(PlayStreamWhenReady(strURL, source));
}

private IEnumerator PlayStreamWhenReady(string strURL, AudioSource Source)
{
WWW www = new WWW(strURL); // start a download of the given URL

Logger.LogInfo(LogGroups.Audio, "WWW Bytes: " + www.bytesDownloaded);
Logger.LogInfo(LogGroups.Audio, "WWW Error: " + www.error);
Logger.LogInfo(LogGroups.Audio, "WWW URL: " + www.url);

if (www.error == null)
{

Logger.LogInfo(LogGroups.Audio, “WWW GetAudio”);
Source.clip = www.GetAudioClip(false, true); // 2D, streaming

while (!Source.clip.isReadyToPlay)
{
Logger.LogInfo(LogGroups.Audio, “Not Ready - Yielding!”);
yield return null;
}

Logger.LogInfo(LogGroups.Audio, “WWW Playing”);
Source.Play();
}

}

strURL is a full file://C:\Project.… filepath to the .mp3 file. This running in the editor will always print - “Not Ready - Yielding!”

It is never marked as ready
If I use c.Clip = www.audioclip it will work, GetAudio() will not… but then it’s not streaming right?

Seems like a long time with no reply to the original message here, and I see a lot of similar type stuff around the internet, some saying it’s a Unity bug still in existence… can anyone help with this?