I need to download audio (OGG, Mp3 or wav) from URL and play it.
In Editor is working fine, and also in stand alone build.
But not in WebGL build.. i got any error or (depends on format) this:
Streaming of 'mpeg' on this platform is not supported UnityEngine.Networking.DownloadHandlerAudioClip:GetContent(UnityWebRequest)
My Code:
// Here audio is downloaded based on audioURL ... WWW data = new WWW(audioURL); yield return data; AudioClip downloadedClip = data.GetAudioClipCompressed(false, AudioType.OGGVORBIS) as AudioClip; if (downloadedClip != null) { _audio.clip = downloadedClip; } ...
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;
}
To download clip i've used also (instead first code part):
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;
}
}
For some reason, audio in webgl isn't played.
EDIT 1: When uploading MP3 , error (also in editor) is:
Streaming of 'mpeg' on this platform is not supported UnityEngine.Networking.DownloadHandlerAudioClip:GetContent(UnityWebRequest)
I solved upgrading to 2018.4.
Now it works with MP3 without problems.