I’m trying to make an audioloader so the user can choose his/her own music, but i’m running into a problem i don’t know how to solve. Whatever audioformat i try, unity will always say the file format is not supported. I’m currently using 2018.2, but in earlier versions unity would just give me a blank error and not tell me anything. Here’s my code, i copied the entire thing straight from this Unity - Scripting API: Networking.UnityWebRequestMultimedia.GetAudioClip, and added a delay so the requester can finish downloading, any ideas? The file does exist, it plays when i click it.
IEnumerator GetAudioClip(string directory)
{
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("file://D:/audio.wav", AudioType.WAV))
{
yield return www.SendWebRequest();
while (!www.isDone)
{
yield return new WaitForEndOfFrame();
}
if (www.isNetworkError)
{
Debug.Log(www.error);
}
else
{
AudioClip myClip = DownloadHandlerAudioClip.GetContent(www);
transform.GetComponent<AudioSource>().clip = myClip;
transform.GetComponent<AudioSource>().Play();
}
}
}