Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Publish webgl using network audio error message JS_Sound_GetLoadState

Discussion in 'Audio & Video' started by lizhenjie1009, Nov 27, 2023.

  1. lizhenjie1009

    lizhenjie1009

    Joined:
    Nov 27, 2023
    Posts:
    2

    Using UnityWebRequestMultimedia GetAudioClip retrieves network audio and runs normally in the editor, but when published to webgl and opened using Chrome browser, an error message appears。

    The Unity version used is 2021.3.0f1



    View attachment 1337047


    Error Message:
    An error occurred running the Unity content on this page. Seeyour browser JavaScript console for more info. The error was:TypeError: Cannot read properties of undefined (reading 'error)at Js Sound GetLoadState (blob:http://127.0.0.1:8080/48b0013a-6f7b-4ed4-8e83ca2a9cf09756:3 46483)at wasm://wasm/06479





    Code (CSharp):
    1. IEnumerator PlayAudioClip(string audioUrl,Action<AudioClip> callback)
    2.         {
    3.             using UnityWebRequest audioRequest = UnityWebRequestMultimedia.GetAudioClip(audioUrl, AudioType.WAV);
    4.             yield return audioRequest.SendWebRequest();
    5.  
    6.             if (audioRequest.result != UnityWebRequest.Result.Success)
    7.             {
    8.                 Debug.Log("Failed to load audio: " + audioRequest.error);
    9.             }
    10.             else
    11.             {
    12.                 AudioClip audioClip = DownloadHandlerAudioClip.GetContent(audioRequest);
    13.                 callback(audioClip);
    14.             }
    15.         }
     

    Attached Files:

  2. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    379
    What is the format of the audio element you are retrieving? do it behave differently if you change that type?

    Also, based on your code the error could be happening in the callback. Would it be possible to expand what is going on in there?

    Thanks!
     
  3. lizhenjie1009

    lizhenjie1009

    Joined:
    Nov 27, 2023
    Posts:
    2



    1. I have tried both MPEG and WAV audio formats and they perform consistently

    2. The callback did not have any errors, but in the editor clip.length is normal length, but in the webgl length is 0