MsMete
August 7, 2014, 4:08pm
1
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???
gregzo
August 8, 2014, 4:43pm
2
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:
Cheers,
Gregzo
MsMete
August 8, 2014, 5:24pm
3
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??
gregzo
August 8, 2014, 6:41pm
4
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.
gregzo
August 8, 2014, 6:44pm
5
Also, as with all things I/O, always check that the file exists. Use the System.IO namespace, it has great classes to work easily with the file system - File, FileInfo, Directory and DirectoryInfo are musts, so is Path.
MsMete
August 9, 2014, 4:05am
6
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