2

A new Delphi 10.4.2 macOS project attempts to record microphone audio but gets this error message in a pop up window:

"Unauthorized to record audio."

How does a Delphi app get authorization to record audio?

I started with blank project so...

Project | Options | Application | Version Info | Key NSMicrophoneUsageDescription is set to the default string of "The reason for accessing the microphone"

The exception is being raised here in FMX.Media.AVFoundation:

    {$ELSEIF DEFINED(MACOS)}
  if TOSVersion.Check(10, 14) and (TAVCaptureDevice.OCClass.authorizationStatusForMediaType(AVMediaTypeAudio) <> AVAuthorizationStatusAuthorized) then
    raise ECaptureDeviceException.Create(SAudioCaptureUnauthorized);
{$ENDIF}
Mike at Bookup
  • 1,211
  • 14
  • 32
  • 1
    "attempts to record microphone audio".. using which code? "How does a Delphi app get authorization to record audio?" If using `TAVAudioCaptureDevice` it should be doing this for you, otherwise you'd need to call `TAVCaptureDevice.OCClass.requestAccessForMediaType` yourself (checking if macOS 10.14 or higher), passing `AVMediaTypeAudio` for the `mediaType` – Dave Nottage Apr 19 '21 at 01:09
  • Added the code to the question. – Mike at Bookup Apr 19 '21 at 02:26
  • 1
    It appears I was mistaken about it requesting permission for you, and that you should explicitly call `RequestPermission` on the `TAVAudioCaptureDevice` instance. You could use the `OnPermissionRequest` event to determine whether or not it was granted – Dave Nottage Apr 19 '21 at 02:32

1 Answers1

4

Adding the call to RequestPermission worked.

procedure TForm1.FormCreate(Sender: TObject);
begin
  fMic := TCaptureDeviceManager.Current.DefaultAudioCaptureDevice;

  {$IFDEF MACOS}
  fMic.RequestPermission;
  {$ENDIF}
end;

Mike at Bookup
  • 1,211
  • 14
  • 32