Search Unity

Audio Audio clip information is wrong in WebGL player when downloaded from a remote server

Discussion in 'Audio & Video' started by gsantos, Sep 8, 2017.

  1. gsantos

    gsantos

    Joined:
    Sep 30, 2012
    Posts:
    7
    Hi guys,

    We're facing an issue when we try to access the AudioClip information after downloading it from a remote server.
    It works on Unity Editor but the same code fails on WebGL.

    Code (CSharp):
    1. using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, audioType))
    2. {
    3.     yield return www.Send();
    4.  
    5.     if (www.isNetworkError || www.isHttpError)
    6.     {
    7.         Debug.Log("Error Downloading audio: " + www.error);
    8.     }
    9.     else
    10.     {
    11.         AudioClip audio = DownloadHandlerAudioClip.GetContent(www);
    12.         if (audio)
    13.         {
    14.             var result = audio.LoadAudioData();
    15.             Debug.Log("LOAD AUDIO DATA RESULT: " + result);
    16.             Debug.Log("AUDIO CLIP LENGTH: " + audio.length);
    17.             Debug.Log("AUDIO CLIP STATE: " + audio.loadState);
    18.             this.audioSource.clip = audio;
    19.         }
    20.         else
    21.         {
    22.             Debug.Log("Problem loading audio");
    23.         }
    24.     }
    25. }
    The logs on WebGL are:
    LOAD AUDIO DATA RESULT: true
    AUDIO CLIP LENGTH: 0 (expected 120 seconds)
    AUDIO CLIP STATE: Unloaded (expected Loaded or Failed)

    Are we missing some step or doing something wrong?

    Thank you very much in advance!
     
    G3nko0 likes this.
  2. gsantos

    gsantos

    Joined:
    Sep 30, 2012
    Posts:
    7
    bump...
     
  3. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    200
  4. pepipe

    pepipe

    Joined:
    Jun 2, 2014
    Posts:
    10
    I will revive this old thread as I'm facing the same problem with Unity 2018.2.18f1 using .wav files from a TTS file. I need the duration to coordinate some stuff and I'm getting 0 from GetComponent<AudioSource>().clip.length when in Unity Editor I get the correct value.

    There's any solution to this? clip.length work with some type of audio? which?

    Thanks,
     
    Last edited: Dec 13, 2018
    GilCat likes this.
  5. Umresh

    Umresh

    Joined:
    Oct 14, 2013
    Posts:
    56
    Bump... I'm facing the same issue but when playing clip it plays but length returned is 0.
     
  6. AymericDavid

    AymericDavid

    Joined:
    Oct 4, 2018
    Posts:
    2
    Same. Length is still 0 (and the sound plays !)
     
  7. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    78
    It's 2021 and this problem is still present.
    And the crazy thing is that it WON'T be fixed.
     
    Last edited: Feb 11, 2021
    G3nko0 likes this.
  8. M-Ansley

    M-Ansley

    Joined:
    Sep 24, 2020
    Posts:
    5
    Running into a similar issue at the moment: we're downloading some audio from a remote server using `UnityWebRequestMultimedia.GetAudioClip(url, AudioType.MPEG)` and `DownloadHandlerAudioClip.GetContent(request)`, and are noticing some differences in the file the moment we've downloaded it between the editor and WebGL.

    When downloaded in the editor, the audio clip has a length of 7.176:
    upload_2023-9-29_15-42-4.png

    Whereas when downloaded in WebGL, using the same methods, the same audio clip has a length of 4.055:
    upload_2023-9-29_15-41-21.png

    So in the editor the clip plays in full, whereas in WebGL the same clip cuts out some of the way through. I'm conscious this may be a bit niche, but the audio clips we're downloading were generated with CereProc and do have some slight audio glitches around the point they're cut short in WebGL. When we paste the URL we used for the request into the same browser the audio plays in full, albeit with the glitch. I'm wondering if somewhere along the line some code is mistaking the audio glitch for the end of the clip somehow?
     
  9. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    410