- Home /
Trying to load and play saved .wav from /Documents iOS
Hey everybody. I'm using UniFileBrowser plugin which returns a file and the path name. All I want to do is use this path to load and play a wav file on iOS. I've been working on this for 18hrs straight, googling www class, posting in other forums, etc. I am desperate for help. Can someone please show me the correct way to write this? It's not returning any errors, but it's also not loading and playing the file...
void OpenFile (string pathToFile) { //OpenFile is apublic funtion of UniFileBrowser
var fileIndex = pathToFile.LastIndexOf (pathChar);
message = "You selected file: " + pathToFile.Substring (fileIndex+1, pathToFile.Length-fileIndex-1);
Fade();
WWW AudioToLoadPath = new WWW("file://" +pathToFile);
Camera.main.audio.clip = AudioToLoadPath.audioClip;
Camera.main.audio.Play();
}
Once I select the file, it returns the name of the file I selected, so that part is working great. I just need help with the correct syntax or how to actually load and play the .wav using the pathToFile. Thanks all!
What do you pass to 'pathToFile'? I am also trying trying to load a wav in iOS but i can't get it to work.
I am giving the FullName of the FileInfo of the wav-file (something like: /var/mobile/.../file.wav)
It's quite an old thread but i'll give it a try :)
Answer by artfish · Oct 30, 2014 at 11:52 PM
I was able to achieve this by using the following: using System.IO;
private WWW musicFile;
public AudioSource musicPlayer;
And to play it, I use
void OpenFile (string pathToFile) {
var fileIndex = pathToFile.LastIndexOf (pathChar);
message = "You selected file: " + pathToFile.Substring (fileIndex+1, pathToFile.Length-fileIndex-1);
Fade();
musicFile = new WWW("file:///" + pathToFile);
audio.clip = musicFile.GetAudioClip(false, false);
musicPlayer.audio.Play ();
Answer by Ludopathic · Jan 04, 2017 at 04:02 PM
You won't need "file:///" + - if you add this you will end up having the filepath twice over when using UniFileBrowser. You should read the documentation, it's pretty self-explanatory.
Your answer
Follow this Question
Related Questions
Why local WWW audio stream not working on iOS? 1 Answer
Speed of WWW 1 Answer
How do I reduce the CPU load spike caused by playing an audio clip? 1 Answer
Generate Chart with Data 0 Answers
Issues with iPad Audio 0 Answers