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

那年仲夏 提交于 2019-12-12 11:08:41

问题


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.


回答1:


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;



回答2:


following fix to the Url solved the problem for me.

fixFileName = mediaFiles[i].fullPath.indexOf('file://') > -1 ? mediaFiles[i].fullPath : "file://" + mediaFiles[i].fullPath;



回答3:


ok. this creepy error was solved.

all i did was made the file extension to uppercase, i.e. made ".wav" to ".WAV".



来源:https://stackoverflow.com/questions/25252295/phonegap-3-5-media-plugin-error-on-ios-failed-to-start-recording-using-avaudior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!