Hello everyone,
Currently on our project I’m saving audio from microphone on the mobile device and saving it as a .wav file successfully to the file system (Application.persistentDataPath). Then I’m using WWW class to access the audio file and using it for playback.
It works completely fine on Editor and Android. But when I built the project for iOS it just doesn’t work. I tried to debug and on the Xcode console there is this error:
Error: Cannot create FMOD::Sound instance for resource \245 , (Operation could not be performed because specified sound/DSP connection is not ready. )
Firstly I thought that was the FMOD problem (which I’m not even using). After long searches on the web I found out that the problem was from the WWW class. I debugged the WWW class and found that the error is “unsupported URL”. When I’m using WWW to get the file, I use (file://) prefix.
Before the www load, I used System.IO to check if the .wav file exists, then load the audio file with www class. I printed the data path every time I use www and checked if there is a case sensitivity problem. Paths are exactly the same. I’m using Coroutines for getting the data with www class. Here is the code:
public IEnumerator loadAudioFromDisk()
{
pathBuilder = new StringBuilder();
if(currentRecordNum == 0)
{
pathBuilder.Append("file://").Append(recordPath1);
}
else
{
pathBuilder.Append("file://").Append(recordPath2);
}
string path = pathBuilder.ToString();
Debug.Log("Trying to get AudioClip from " + path);
www = new WWW(path);
while(!www.isDone)
{
yield return www;
if (!string.IsNullOrEmpty(www.error))
Debug.Log(www.error);
}
loadedAudio = www.GetAudioClip(false,true,AudioType.WAV);
if(loadedAudio.loadState == AudioDataLoadState.Loaded)
{
playback.setAudioClip(loadedAudio,0);
playback.playButton.SetActive(true);
Debug.Log("Record Loaded");
www.Dispose();
}
}
I also tried not using the yield inside while loop, didn’t work. Also tried changing the streaming flag to false when getting the audio clip. At this point I’m starting to think that this is an Unity bug. Strange thing is, it works on Android and Editor completely fine. Anyone can help me with this problem?
Thanks!