Cordova iOS - can't record sound even though the file is created


#1

I am trying to record a sound file using cordova-plugin-media, but I am always getting this error:

{message: “Failed to initialize AVAudioRecorder: (null)↵”, code: 1}

I am first creating the file, like this

iOSCreateFile(fileName, callback) {
    window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, (fs) => {
        fs.root.getFile(fileName, {
            create: true, 
            exclusive: false
        }, (fileEntry) => {
            console.log("fileEntry is file?" + fileEntry.isFile.toString());
            // here I am getting true, so the file is obviously created
            callback(fileEntry.nativeURL);
        }, (error) => {
            console.log('error create file: ' + error);
        });
    }, (error) => {
        console.log('error loading file system: ' + error);
    });
}

The fileEntry.nativeURL I am sending back looks like this

file:///var/mobile/Containers/Data/Application/0EE019AA-EFBA-4FB9-97EC-1F16FFDDA36B/tmp/1496663387924.wav

then, when this calls back, I am doing the following

// that long file path string is passed here
let soundRecord = new Media(filePath, () => {
    // success
    // more code
}, (error) => {
    console.log(error);
});
soundRecord.startRecord();

And once it tries to execute the startRecord(), it gives me the Failed to initialize AVAudioRecorder error…
I also tried not creating a file, but only passing a file name string to the new Media object, like “1240215251.wav”, and it’s supposed to create it for me, but I am still getting the same error.

What am I doing wrong please?


#2

Please post solution if you found it