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!
     
  2. gsantos

    gsantos

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

    BBO_Lagoon

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

    pepipe

    Joined:
    Jun 2, 2014
    Posts:
    4
    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:
    17
    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
unityunity