0
\$\begingroup\$

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.

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)

\$\endgroup\$
  • \$\begingroup\$ Not trying to be insulting - have you triple checked the volume settings? It's possible that it may be playing, but at a significantly lower volume. I've run into similar things before where a different default gets grabbed... \$\endgroup\$ – Pikalek May 15 at 13:39
  • \$\begingroup\$ No, I confirm that volume is up. \$\endgroup\$ – stighy May 15 at 14:55
  • \$\begingroup\$ which unity version you are using? and are u getting any error or warning in browser console? \$\endgroup\$ – Muhammad Faizan Khan May 17 at 9:44
0
\$\begingroup\$

After upgrading to LTS 2018.4 using the same code above, it worked. Maybe there was a bug in 2018.3 ? At the moment works with Mp3 and not ogg.

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;
            }
        }
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.