Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

unitywebrequest hangs firefox in webgl

Discussion in 'Web' started by dansav, May 29, 2019.

  1. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    I'm trying to load an audio clip using webgl and it hangs firefox with a
    "a web page is slowing down the browser do you want to stop it or wait?

    I've tried the following different solutions and playing around with coroutines and yields but all of them give the same result. What is causing the hang up? It's like the browser is stuck in an loop and is not being released.

    Other info: If I press stop it the sound plays but the webgl freezes because the script stops. In the editor this works instantaneously. The audio file is very small and loads quickly in the editor. Unity 2019.


    Code (CSharp):
    1.    
    2. //www version which is still allowed for webgl
    3. public IEnumerator cogetAudioChannel1www(string url)
    4.     {
    5.         Debug.Log("****************************************************getting audio channel www");
    6.         WWW soundClip = new WWW(url);
    7.         Debug.Log(soundClip);
    8.  
    9.         yield return soundClip;
    10.         UnityEngine.Debug.Log("********************************download sound clip progress" + soundClip.progress);
    11.         AudioClip myClip = soundClip.GetAudioClip(false);
    12.             gameObject.GetComponent<AudioSource>().clip = myClip;
    13.                 gameObject.GetComponent<AudioSource>().Play();
    14.                 testingaudio = true;
    15.     }
    16.  
    17. //I tried calling from coroutine just in case
    18. public void getAudioChannel1mp3(string url)
    19.     {
    20.         StartCoroutine(cogetAudioChannel1mp3(url));
    21.     }
    22.  
    23. //unitywebrequest version
    24.     public IEnumerator cogetAudioChannel1mp3(string url)
    25.     {
    26.         using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.MPEG)) {//AudioType.OGGVORBIS
    27.             UnityWebRequestAsyncOperation async = www.SendWebRequest();
    28.             yield return async;
    29.  
    30.             while (!async.isDone) {
    31.                 Debug.Log("progress=" + async.progress);
    32.                 yield return null;
    33.             }
    34.             if (async.webRequest.isNetworkError || async.webRequest.isHttpError) {
    35.                 Debug.Log(www.error);
    36.             } else {
    37.                 AudioClip myClip = DownloadHandlerAudioClip.GetContent(async.webRequest);
    38.                 gameObject.GetComponent<AudioSource>().clip = myClip;
    39.                 gameObject.GetComponent<AudioSource>().Play();
    40.                 testingaudio = true;
    41.             }
    42.         }
    43.     }
     
  2. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    I have since discovered that it is not the Unitywebrequest but the line
    gameObject.GetComponent<AudioSource>().Play(); that Hangs up Firefox.
    The script is attached to a gameObject with an AudioSource, and an Audio Listener.

    I've taken it out of these functions and put it into it's own function which I call after the clip has successfully downloaded. I tried Play(0) and PlayDelayed(0f) and they still hang Firefox in WebGL
     
  3. Jeremy-Alessi

    Jeremy-Alessi

    Joined:
    Oct 18, 2007
    Posts:
    125
    I'm seeing this same behavior in some instances...

    Bump!