Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Share:
Notifications
Clear all

[Solved] Lazarus - MacOS - Play sounds with AudioServicesPlayAlertSound (AudioToolbox)

1 Posts
1 Users
0 Reactions
1,915 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

Since someone was asking for this, and I happened to be playing with something similar; this is how you can play a system sound in Lazarus Pascal on MacOS X:

1) Add the AudioToolbox framework with 

{$linkframework AudioToolbox}

2) Declare the procedure: 

procedure AudioServicesPlayAlertSound (inSystemSoundID: TSystemSoundID); external name '_AudioServicesPlayAlertSound';

3) Declare the sound ID type: 

TSystemSoundID = UInt32;

4) And finally call the function: 

AudioServicesPlayAlertSound(1); // the number 1 can be any other number, depending on the sound you want

So a simple example:

unit Unit1;
{$mode objfpc}{$H+}
interface
{$linkframework AudioToolbox}
uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, MacOSAll, CocoaInt;
type
  { TForm1 }
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  public
  end;
  TSystemSoundID = UInt32;
  procedure AudioServicesPlayAlertSound (inSystemSoundID: TSystemSoundID); external name '_AudioServicesPlayAlertSound';
var
  Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
  AudioServicesPlayAlertSound(1);
  AudioServicesPlayAlertSound(2);
end;
end.


   
ReplyQuote
Share: