Mike at Bookup
Mike at Bookup

Reputation: 1324

Delphi MacOS project gets Error "Unauthorized to record audio"

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}

Upvotes: 2

Views: 166

Answers (1)

Mike at Bookup
Mike at Bookup

Reputation: 1324

Adding the call to RequestPermission worked.

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

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

Upvotes: 4

Related Questions