0

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)

gman
  • 100,619
  • 31
  • 269
  • 393
stighy
  • 7,260
  • 25
  • 97
  • 157
  • Judging by the error, I'd guess that your file is not actually mp3 or ogg, but mpeg file format. I'm not sure _why_ streaming mpeg files isn't supported in webgl, but judging by that error you won't get it working. Have you tried it with a different audio file that you're **absolutely** sure is MP3 or OGG? I'd suggest just exporting a file from something like Audacity to make sure you're definitely using the file format you expect. – Richard Johnson May 15 '19 at 15:24
  • I've tried to convert to mp3 to be sure, with no luck! – stighy May 15 '19 at 21:04

3 Answers3

1

Unity document mentioned the audio format should be natively supported by the browser, you can check the support state from this link:

https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats

Or simply use audio tag to check the file.

As I tested ago, ogg suits chrome and firefox, and mp3 suits safari

shingo
  • 18,436
  • 5
  • 23
  • 42
0

"Mp3" is short for MPEG-3; and indeed, if you look at Unity's AudioTypes, it explicitly defines the MPEG AudioType as "MP2/MP3 MPEG."

So basically: try using a non-mp3 file.

-1

I solved upgrading to 2018.4.

Now it works with MP3 without problems.

stighy
  • 7,260
  • 25
  • 97
  • 157