Search Unity

Audio WWW.GetAudioClip stopped working

Discussion in 'Audio & Video' started by drcrck, Dec 1, 2018.

  1. drcrck

    drcrck

    Joined:
    May 23, 2017
    Posts:
    328
    I upgraded from 2017 to 2018.2 today and WWW.GetAudioClip stopped working for some of my .wav files
    The code is simple:

    Code (CSharp):
    1.  
    2. var url = "file://" + filename;
    3. var audioLoader = new WWW(url);
    4. while (!audioLoader.isDone) {}
    5. var clip = audioLoader.GetAudioClip(false, false, AudioType.WAV);
    6. Debug.Log(clip.length);
    7. clips.Add(clip);
    8.  
    50% of the files that worked before now can't loaded, clip.length is 0
    I can't find anything related to this method in the 2018's patch notes
    When was it changed? Any ways to fix it?

    Example of .wav that worked fine in 2017 and can't be loaded with WWW in 2018:
    https://cdn.discordapp.com/attachments/449340820072693780/518413164405325830/sample.wav
     
  2. KRSBX

    KRSBX

    Joined:
    Nov 18, 2016
    Posts:
    10
    you could use ienumerator for downloading the file
    Code (CSharp):
    1.     public string url = null;
    2.     WWW audioLoader;
    3.     public AudioClip clip;
    4.     public AudioSource audio;
    5.     public int id = 0;
    6.     // Use this for initialization
    7.     void Start () {
    8.         audio = gameObject.GetComponent<AudioSource> ();
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update () {
    13.         if (Input.GetMouseButtonDown (0)) {
    14.             if (id < 1) {
    15.                 StartCoroutine (audioDownload ());
    16.                 id++;
    17.             }
    18.             if (!audio.isPlaying) {
    19.                 audio.Play ();
    20.             }
    21.         }
    22.     }
    23.  
    24.     IEnumerator audioDownload(){
    25.         using (audioLoader = new WWW (url)) {
    26.             yield return audioLoader;
    27.             Debug.Log ("Downloaded");
    28.             clip = audioLoader.GetAudioClip (false, false, AudioType.WAV);
    29.             audio.clip = clip;
    30.         }
    31.     }
     
  3. drcrck

    drcrck

    Joined:
    May 23, 2017
    Posts:
    328
    yeah it could be refactored to a coroutine but I doubt it would save more than 100ms of loading time
    and it has nothing to do with the described issue anyway
     
  4. KRSBX

    KRSBX

    Joined:
    Nov 18, 2016
    Posts:
    10
    After i try it, it works perfectly do you already try it? 'cause when i try it with coroutine, it works perfectly and fix the issues.