Issue with nativescript-audio


#1

Hi,

I’m trying to use the nativescript-audio plugin (on iOS platform for now, with permissions granted in Info.plist file).
The TNSPlayer methods works fine, but I always get this error

CONSOLE LOG file:///app/tns_modules/nativescript-audio/src/ios/recorder.js:26:32: setCategoryError: null

when I use TNSRecorder.start() method with the code below :

public startRecord() {
        if (TNSRecorder.CAN_RECORD()) {

        var audioFolder = knownFolders.currentApp().getFolder("audio");
        
        console.log("audioFolder : " + JSON.stringify(audioFolder));

        let androidFormat;
        let androidEncoder;
        if (platform.isAndroid) {
            // m4a
            // static constants are not available, using raw values here
            // androidFormat = android.media.MediaRecorder.OutputFormat.MPEG_4;
            androidFormat = 2;
            // androidEncoder = android.media.MediaRecorder.AudioEncoder.AAC;
            androidEncoder = 3;
        }

        let recordingPath = audioFolder.path + "/recording." + this.platformExtension();
        let recorderOptions: AudioRecorderOptions = {

            filename: recordingPath,

            format: androidFormat,

            encoder: androidEncoder,

            metering: true,

            infoCallback: (infoObject) => {
                console.log("infoCallback : " + JSON.stringify(infoObject));
            },

            errorCallback: (errorObject) => {
                console.log("errorCallback : " + JSON.stringify(errorObject));
            }
        };


        this.recorder.start(recorderOptions).then((result) => {
            this.set("isRecording", true);
            if (recorderOptions.metering) {
                //this.initMeter();
            }
        }, (err) => {
            this.set("isRecording", false);
                //this.resetMeter();
            dialogs.alert(err);
        });
        } else {
            dialogs.alert("This device cannot record audio.");
        }
  }

Can anyone give a suggest for this?

Thanks in advance.

Regards,


#2

Did you resolve your issues here?

I am having similar problems. See: Nativescript-audio plugin errors: 'Error Domain' and 'null is not an object'


#3

Hi @WS123,

I did not go back to this specific problem with audio plugin, but I had similar problem with Image saving.
It was due to the use of currentApp() instead of documents().

Indeed, currentApp() gets the root folder for the current application, but on iOS, this folder is read-only, contrary to documents().

If you develop your app on iOS device, using documents() method could solve the problem.


#4

@Chris, Thanks very much for your reply. I will take a look at the currentApp() v documents() issue.