Hello. I’m trying to download at runtime, various audio file format : Mp3 , Ogg, Wav but I can’t play it at runtime.
This is my code:
WWW data = new WWW(audioURL); yield return data;
AudioClip downloadedClip = data.GetAudioClipCompressed(false, AudioType.OGGVORBIS) as AudioClip;
if (downloadedClip != null)
{
_audio.clip = downloadedClip;
}
…
This code to play Audio:
public void PlayAudio() {
// Here clip is play
if (_audio.clip != null && _audio.isPlaying == false)
_audio.Play();
else
Debug.Log(“Background music not present!”);
_audio.loop = true;
}
I’ve also try to download Audio using this code:
using (UnityWebRequest www2 = UnityWebRequestMultimedia.GetAudioClip(audioURL, AudioType.OGGVORBIS))
{
yield return www2.SendWebRequest();
if (www2.isHttpError)
{
Debug.Log(www2.error);
LogAdd(www.error, true);
}
else
{
AudioClip downloadedClip = DownloadHandlerAudioClip.GetContent(www2);
_audio.clip = downloadedClip;
}
}
I can’t use AssetBundle because my web app is interactive: user can upload file (audio) then they will be reproduced later.
Can you help me ?
Thanks