Hi community,
I have a problem with importing an audiofile.
Im using this code as a coroutine to load an audio file after I opened in in the filebrowser:
private IEnumerator loadAudio(string url) {
WWW www;
if (url.EndsWith (".mp3")) {
Mp3ToWav (url, "currentlyplayed.wav");
www = new WWW ("D:/Users/PC-Benutzer/Documents/SoundEditing/currentlyplayed.wav");
} else {
www = new WWW (url);
}
yield return www;
if (www != null && www.isDone) {
audioclip = www.GetAudioClip (false,false);
audiosource.clip = audioclip;
audiosource.loop = false;
audiosource.Play ();
loading=false;
}
}
At first I check if the file is a wav or mp3 file. If its a mp3 file I will convert it and save it in a wav file (currentlyplayed.wav). The problem I have is in the second part of the function.
The audioclip of the www object is still empty. I tried everything i could think of to get the audioclip from the www object to my audiosource. When I tried to copy the data with GetData()/SetData() i got this error:
AudioClip.GetData failed; AudioClip contains no data.
The wav file I’m using for testing works fine when played in a normal media player so I know that the file isnt corrupted.
Can you help me to solve this problem?