- Home /
RAM problem loading a lot of sound files using WWW.
I am using WWW in csharp to load thousands of sound clips one at a time stored in a folder on my computer. Every time I load a sound using WWW www = new WWW(file path); and play it, memory usage grows. Is there anyway to clear the previously loaded files from memory. After around 1600 loaded and played files, nothing can be loaded.
Here is my csharp code:
using UnityEngine;
using System.Collections;
using System.IO;
public class audioLoad : MonoBehaviour {
public string path = "c:/oggunity/";
public bool randomize = true;
public float minWaitTime = 0f;
public float maxWaitTime = 5f;
public float waitTime=0f;
public float counter =0f;
public int actualClip=0;
public string[] files;
WWW wwwFile;
private bool gate=true;
private int previousClip;
public string actualFile;
// Use this for initialization
void Start () {
files=Directory.GetFiles(path,"*.ogg");
}
// Update is called once per frame
void Update () {
if(!audio.isPlaying && audio.clip.isReadyToPlay)
{
if (gate==true)
{
if(randomize)
{
do{actualClip=Random.Range(0,files.Length);}while(actualClip==previousClip);
previousClip=actualClip;
}
else
{
if (actualClip<files.Length-1)actualClip++; else actualClip=0;
previousClip=actualClip;
}
wwwFile = new WWW ("file:///"+files[actualClip]);
Debug.Log("new file loaded");
actualFile=files[actualClip];
gate=false;
}
if (counter<waitTime)
{
counter+=Time.deltaTime;
}
else
{
audio.clip=wwwFile.audioClip;
audio.Play();
}
}
if(audio.isPlaying && gate == false)
{
gate=true;
counter=0f;
waitTime=Random.Range(minWaitTime,maxWaitTime);
}
}
}
Answer by snow404 · Sep 02, 2013 at 06:45 PM
To free the memory :
Resources.UnloadUnusedAssets();
Your answer
Follow this Question
Related Questions
Loading text from web or RSS using WWW class 1 Answer
How I can run start function before showing scene? 1 Answer
How can I load pre-compressed textures at run-time (without using assetBundles) 3 Answers
Load images from www to prefab clones? 0 Answers
loading from disk, saving to database 0 Answers