- Home /
 
[SOLVED] Load audio file saved in cache
Edit: Solution was to add "file://" before the path when using WWW locally like this.
Hi,
My goal is to load a downloaded audio file saved in the cache (see code snippet), but I can't get it to work. I have tried using www.audioClip locally (see code) but without success. Any help is much appreciated!
    /*** In my DownloadScript: ***/
 
     //Successfully downloaded the audio and saved it in the cache:
     File.WriteAllBytes(Application.persistentDataPath + "/audioFilename", www.bytes);
     
 
 
     /*** In my LoadingScript: ***/
     
     LoadAudioFile()
     {
         StartCoroutine(LoadAudioWithWWW(_downloadedAudioFile.FilePath));
     }
     
     IEnumerator LoadAudioWithWWW(string audioFilePath)
     {
         using (WWW www = new WWW(audioFilePath)) //SOLUTION: "file://" + audioFilePath
         {
             while (!www.isDone)
                     yield return null;
                
             if (www.error != null)
                     Debug.Log ("Error occured!"); //<--- THIS HAPPENS when using WWW with local path
             
             AudioClip audioClip = www.audioClip;
         }
     }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by LouiseW · May 24, 2015 at 03:36 PM
Solution was to add "file://" before the path when using WWW locally like this. So on line 17 in my code snippet above, the correct line would be:
  using (WWW www = new WWW("file://" + audioFilePath))
 
               (Big thanks to aihodge from the Unity3D forum!)
Your answer