Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap 3.5 Media Plugin Error on iOS "Failed to start recording using AvAudioRecorder"

I am trying to let users record an audio file in a Phonegap app. It works well on Android, but on iOS I get the following error when the recording should start:

"Failed to start recording using AvAudioRecorder".

I use a .wav filename, I create the file first, I have followed all instructions I have found and I keep getting the error.

This is the 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 is successfully created. Then I get the error.

Media plugin version is 0.2.11

I don't know what else to try. Thanks for any help.

like image 584
Vero Avatar asked Aug 11 '14 20:08

Vero


1 Answers

I solved this myself.

I'll leave solution here in case it helps someone.

For iOS, this needs to be changed:

mediaFileURL = fileEntry.toURL();

to this:

mediaFileURL = fileEntry.fullPath;

Also, even though I was requesting the Persistent filesystem, iOS saved the file in the tmp folder. So to upload the file afterwards using FileTransfer, I used this to refer to the file (I tried different approaches and this was the one that worked):

sendFileURL = cordova.file.tempDirectory + filename;
like image 122
Vero Avatar answered Nov 12 '22 12:11

Vero