- Home /
Is it possible to load an audio file at runtime?
i need to load audio files at runtime and set them as clips in an audio source(s) currently ive gotten it to find a .wav file with
WWW www = new WWW("file://" + Application.persistentDataPath +"FILE.wav"); and then set it with,
clip1 = www.GetAudioClip(true, true); aud.clip = clip1;
the audio source in the inspector shows a clip, but its empty (nothing to play).
is it even possible to load an audio file from a persistent data path? or am i just out of luck?
Answer by LT23Live · May 02, 2015 at 01:09 AM
if you can load any other file it should be possible as long as it is set in the correct folder and referenced properly. but it would be better to be pre-Incorporated into the engine.
it would be better. however i want the users to be able to load in their own sound files.
Answer by Elchtest · Sep 08, 2016 at 04:27 PM
Just ran into this as well. It helps to give the clip a name for better viewing in the Inspector.
clip.name = "newClip";
In my case, the file was not finished loading when I initiated play(). The while loop below runs until it is done loading.
while(clip.loadState != AudioDataLoadState.Loaded) {
//Debug.Log("Waiting to load audio clip.");
}
audioSourceComponent.clip = clip;
audioSourceComponent.Play();