# IOS Load AudioClip from /Documents Folder

**URL:** https://discussions.unity.com/t/ios-load-audioclip-from-documents-folder/546218
**Category:** Mobile
**Tags:** Scripting
**Created:** [August 7, 2014, 4:08pm UTC](https://discussions.unity.com/t/ios-load-audioclip-from-documents-folder/546218 "2014-08-07T16:08:08Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![MsMete](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@MsMete](https://discussions.unity.com/u/MsMete)
#### Post date: [August 7, 2014, 4:08pm UTC](https://discussions.unity.com/t/ios-load-audioclip-from-documents-folder/546218/1 "2014-08-07T16:08:08Z")

</div>

Hi,

I use this code for iOS path:

- publicstaticstringGetiPhoneDocumentsPath()
- {
- string path =Application.dataPath.Substring(0,Application.dataPath.Length-5);
- path = path.Substring(0, path.LastIndexOf(‘/’));
- return path +“/Documents”;
- }

Documents folder include many .wav files. I want to play this audioClips.

I try this code:

- string filepath =Path.Combine(GetiPhoneDocumentsPath(),SongName);
- AudioClipmy=(AudioClip)Resources.Load(filepath,typeof(AudioClip));
- audio.clip =my;
- audio.Play();

but didn’t work, music is didn’t play ☹

How can I do???

---

<div class="post-metadata">

### Author: ![gregzo](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gregzo/32/131860_2.png) [@gregzo](https://discussions.unity.com/u/gregzo)
#### Post date: [August 8, 2014, 4:43pm UTC](https://discussions.unity.com/t/ios-load-audioclip-from-documents-folder/546218/2 "2014-08-08T16:43:23Z")

</div>

Resources.Load only works for audio in your Resources folder, not for user audio.

You should use the WWW class. It has a handy GetAudioClip function, and loads async:

> **[Unity - Scripting API: WWW](https://docs.unity3d.com/ScriptReference/WWW.html)**

Cheers,

Gregzo

---

<div class="post-metadata">

### Author: ![MsMete](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@MsMete](https://discussions.unity.com/u/MsMete)
#### Post date: [August 8, 2014, 5:24pm UTC](https://discussions.unity.com/t/ios-load-audioclip-from-documents-folder/546218/3 "2014-08-08T17:24:37Z")

</div>

xCode Error line:  
UIApplicationMain(argc, argv, nil, [NSString stringWithUTF8String:AppControllerClassName]);  
error:  
libc++abi.dylib: terminate called throwing an exception

I try WWW.  
Worked on computer(MacOs) but didn’t work on iOS ☹

my code:

void Start() {  
string link = “file://” + GetiPhoneDocumentsPath () + “/” + soundName;  
Debug.Log (link);

StartCoroutine(loadMusic(link));  
}

void Update (){

if (musicLoader != null && musicLoader.isDone && !audio.isPlaying) {  
audio.clip = musicLoader.GetAudioClip(false,false);  
audio.Play();  
}  
}

publicstaticstringGetiPhoneDocumentsPath ()  
{

string path = Application.dataPath.Substring (0, Application.dataPath.Length - 5);  
path = path.Substring(0, path.LastIndexOf(‘/’));  
return path + “/Documents/Raw”;

}

WWWmusicLoader;  
IEnumerator loadMusic (stringlink){  
musicLoader = newWWW (link);  
yield return musicLoader;

}

What is wrong??

---

<div class="post-metadata">

### Author: ![gregzo](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gregzo/32/131860_2.png) [@gregzo](https://discussions.unity.com/u/gregzo)
#### Post date: [August 8, 2014, 6:41pm UTC](https://discussions.unity.com/t/ios-load-audioclip-from-documents-folder/546218/4 "2014-08-08T18:41:38Z")

</div>

Use Application.persistentDataPath instead. Log it first ( running on the device, not the editor ) to make sure where it’s pointing, I forgot if it point to the Documents folder or one step higher.

---

<div class="post-metadata">

### Author: ![gregzo](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gregzo/32/131860_2.png) [@gregzo](https://discussions.unity.com/u/gregzo)
#### Post date: [August 8, 2014, 6:44pm UTC](https://discussions.unity.com/t/ios-load-audioclip-from-documents-folder/546218/5 "2014-08-08T18:44:26Z")

</div>

Also, as with all things I/O, always check that the file exists. Use the [System.IO](http://System.IO) namespace, it has great classes to work easily with the file system - File, FileInfo, Directory and DirectoryInfo are musts, so is Path.

---

<div class="post-metadata">

### Author: ![MsMete](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@MsMete](https://discussions.unity.com/u/MsMete)
#### Post date: [August 9, 2014, 4:05am UTC](https://discussions.unity.com/t/ios-load-audioclip-from-documents-folder/546218/6 "2014-08-09T04:05:56Z")

</div>

Thank you gregzo 🙂 My code is working. My fault is filename invalid character. 🙂  
I use :

foreach(char c in System.IO.Path.GetInvalidFileNameChars() ) {  
newPath = newPath.Replace(c, ‘\_’);  
}

And work 🙂 Thank you very much 🙂
