I have written a wav file into the external storage of the Android device with my unity app using:
string fullPath = Application.persistentDataPath + "/test.wav";
I know the file was created and I can find it on my device using the folder browser on my phone.
The issue is that I cannot find a way to load the file from the external storage into an AudioClip, and hence I am unable to play it.
My attempt to load the file into an AudioClip:
IEnumerator playClip(string path)
{
if (debugText!=null)
debugText.text = "playClip";
var audioLoader = new WWW("file://" + path);
while( !audioLoader.isDone )
yield return null;
AudioClip clip1 = audioLoader.GetAudioClip(false, false);
if (debugText!=null)
debugText.text = audioLoader==null?"www null":"getClip";
// clip1.LoadAudioData();
while(clip1.loadState!=AudioDataLoadState.Loaded){
if (debugText!=null)
debugText.text = "state: "+clip1.loadState;
if (clip1.loadState==AudioDataLoadState.Failed)
{
yield break;
}
yield return null;
}
if (debugText!=null)
debugText.text = "loaded "+clip1.loadState;
}
However, I am always stuck with the debug Text showing “state: unloaded”.
So the AudioClip didn’t load.
Is it possible that AudioClip cannot load wav files on Android?(eventhough my Android can play the wav file)
Should I just use ogg files?
Not sure what else is the issue…
Thanks