Hi, I am struggling to find a solution for this problem. I am downloading mp3 file from internet, saving it locally and I want to put it into an AudioSource clip. But it is not working for me. Clip just becomes blank field in inspector and no sound is being played. Here's my code:
IEnumerator LoadAudioClip(string filePath)
{
Debug.Log("file://" + filePath);
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("file://" + filePath, AudioType.MPEG))
{
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.LogError(www.error);
}
else
{
audioSource.clip = DownloadHandlerAudioClip.GetContent(www);
audioSource.Play();
}
}
}
I could just use UnityWebRequestMultimedia.GetAudioClip straight from the internet, without saving the file locally I suppose, but I wasn't able to get it working. I was getting 400 and 422 response codes, because I also need to send body with the post request. But now I got code that downloads the file without Unity libraries.