TypeError: null is not an object (evaluating '_this._recorder.meteringEnabled = false')

ios

#1

Newbie here.

Get the following error when stopping the recording.

Please see code below. I’m sure I’m doing something wrong. No file is getting created whether I use currentApp() or documents().

Please help!

Thank you!!!

var observable = require(“data/observable”);
var fs = require(“file-system”)
var audio = require(‘nativescript-audio’);
var permissions = require(‘nativescript-permissions’);

var data = new observable.Observable({});
var recorder;

function onNavigatingTo() {
var page = args.object;
page.bindingContext = data;
data.set(‘isRecording’,false);
}
exports.onNavigatingTo = onNavigatingTo;
/*
exports.startRecording = function() {
alert(JSON.stringify(audio));
};
exports.stopRecording = function() {
alert(JSON.stringify(audio));
};
var isMeteringEnabled: bool {get set }
*/

function startRecording(args) {

if(audio.TNSRecorder.CAN_RECORD()) {
    recorder = new audio.TNSRecorder(); //was currentApp().
    var audioFolder = fs.knownFolders.currentApp().getFolder("audio");
    
    var AudioRecorderOptions = {
        filename: audioFolder.path + '/recording.mp3',
        enableMetering: true,
        infoCallback: function() {
            console.log("infoCallback");
        },
        errorCallback: function() {
            console.log("errorCallback");
            alert("Error recording");
        }
    };
    console.log("RECORDER OPTIONS: " + JSON.stringify(AudioRecorderOptions));
    
    recorder.start(AudioRecorderOptions).then(function(res) {
        data.set('isRecording', true);
        if(AudioRecorderOptions.metering) {
            this.initMeter();
        }
    }, function(err) {
           data.set('isRecording', false);
           this.resetMeter(); 
           console.log("ERROR: " + err);
        });
   } else {
        alert("This device cannot record audio");
   }

}
exports.startRecording = startRecording;

/* STOP RECORDING */

function stopRecording(args) {
if(recorder != undefined) {
recorder.stop().then(function () {
this.resetMeter();
data.set(‘isRecording’, false);
alert(‘Audio Recorded Successfully’);
},
function (err) {
data.set(‘isRecording’, false);
this.resetMeter();
alert(‘Audio Recorded Successfully’);
console.log("ERROR: " + err);
});
}
}
exports.stopRecording = stopRecording;


#2

currentApp() is read only in iOS, when you do with documents(), did you make sure your audio directory was created before you use it?


#3

Audio director? Not sure what that is.


#4

Sorry, I meant to say directory / folder, typo mistake.


#5

No worries! Actually no. The folder was already there although. Just no .mp3 file gets created.

Do I have to have a microphone connected to my Mac mini to generate he file? Right now I don’t have a mic connected. I shouldn’t right? Shouldn’t it just create a file with no sound?

Also what file types are generated? .wav, .mp3?

Thanks!