nativescript-audio icon indicating copy to clipboard operation
nativescript-audio copied to clipboard

Android - Info and Error callbacks are required in Recorder

Open MartinMitro opened this issue 7 years ago • 2 comments

There is no check in android recorder.ts class if errorCallback or infoCallback was provided. Therefore when error or info is raised, you will get options.infoCallback / options.errorCallback is not a function error.

MartinMitro avatar Jan 16 '18 12:01 MartinMitro

This is an old one, but I run into related issues today.

There is a mismatch between the type declaration of AudioRecorderOptions and its usage in the implementation of android version of TNSRecorder.

The type declaration of AudioRecorderOptions lists infoCallback and errorCallback as optional fields.

  errorCallback?: Function;
  infoCallback?: Function;

but in Android/recorder.ts, they are referenced without a guard.

...
            onError: (recorder: any, error: number, extra: number) => {
              options.errorCallback({ recorder, error, extra });
            }

This crashed my app since I didn't provide these two options at first.

There are several ways to address the issue: change the type of AudioRecorderOptions, add conditional guard in recorder.ts, or add a default callback. I am not sure which way makes more sense, so I'll skip a PR and just raise the issue.

swiperthefox avatar Jun 10 '21 15:06 swiperthefox

Once again, old issue, but thinking about addressing this with a PR because I keep running into it with a current project. Any input on what option from @swiperthefox would be best?

  • Create a conditional guard in recorder.ts
  • Create a default callback
  • Change the AudioRecorderOptions type to match implementation

This would be my first open-source contribution so any help is appreciated!

lappjeff avatar Jan 17 '22 16:01 lappjeff