Phonegap 3.5 iOS Media Plugin Error "Failed to start recording using AvAudioRecorder"
I am trying to allow users to record an audio file in a Phonegap app. It works fine on Android, but on iOS I get the following error when I start recording:
"Failed to start recording using AvAudioRecorder."
I am using the filename .wav, I create the file first, I followed all the instructions I found and I keep getting the error.
This is a piece of code:
theFileSystem.root.getFile(filename,{create:true},function(fileEntry){
mediaFileURL = fileEntry.toURL();
console.log('Created file ' + mediaFileURL);
mediaRec = new Media(mediaFileURL, function(){
//console.log('Media File created');
}, function(err){
alert('Error creating the media file: ' + err.message);
console.log(mediaFileURL);
for(k in err){
console.log(k + ': ' + err[k]);
}
stopRecordingFile();
});
mediaRec.startRecord();
},function(err){
alert("Error setting audio file");
});
I see the console message "Created file ...", so the file was successfully created. Then I get the error.
Plugin version for multimedia - 0.2.11
I don't know what else to try. Thanks for any help.
source to share
I solved it myself.
I'll leave the solution here in case it helps anyone.
For iOS, this needs to be changed:
mediaFileURL = fileEntry.toURL();
:
mediaFileURL = fileEntry.fullPath;
Also, even though I requested a persistent file system, iOS saved the file in the tmp folder. So to upload the file afterwards using FileTransfer, I used this to link to the file (I tried different approaches and this was the one that worked):
sendFileURL = cordova.file.tempDirectory + filename;
source to share