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