Cordova media plugin ios "Failed to start recording using AVAudioRecorder code:1"

461 Views Asked by At

This question is asked before but its accepted answer does not work. The problem is that I cannot record audio on ios using cordova/ionic 2 application, I have tried the ionic native which fails without error, now trying the cordova-media-plugin which gives the error:"Failed to start recording using AVAudioRecorder code:1". here is my code

      this.file.createFile(this.dir, this.filename, true).then(f => {
        this.m = new (<any>window).Media(this.dir + this.filename,function(e){alert('Success');},
    function(e){alert('failed'+JSON.stringify(e));});
this.m.startRecord();
   }).catch(e=>alert(JSON.stringify(e)));

this.dir has the value of tempDirectory and filename is .wav same result with mp3

Please help, Thanks

1

There are 1 best solutions below

1
Enzo B. On

It's can be a permisson problem cause on a old version of this plugin (cordova 3.0) the code 1 was :

Missing Android permission

To be sure you have the permission to record you can used this plugin

An example :

cordova.plugins.diagnostic.isMicrophoneAuthorized(function(authorized){
    if (authorized) {
        // Do something
    } else {
        // Do something else
    }
}, function(error){
    console.error(error);
});