Link to home
Start Free TrialLog in
Avatar of LeTay
LeTay

asked on

Produce a sound in Delphi

I would like to produce a sound, says one note of music, for several seconds in Delphi
Is there an easy way to do it ?
Avatar of Geert G
Geert G
Flag of Belgium image

beep
but that might sound a little like roundrunner ... via the pc speaker

or via uses MMSystem and PlaySound

uses MMSystem;

procedure TForm1.Button1Click(Sender: TObject);
begin
  PlaySound('Open', 0, SND_ALIAS or SND_ASYNC);
end;

Open in new window


a list of what system sounds can be played is in HKCU/AppEvents/EventLabels

Other eventlabels instead of 'Open':
'WindowsLogon', 'WindowsLogoff', etc ...
Avatar of LeTay
LeTay

ASKER

I tried your sample, but no sound came out
Let's say I want to have a specific music note played for 3 seconds.
What should I code ?
turning your volume up might help

if you can't get that tiny sample to work, why look further ?
Avatar of LeTay

ASKER

Volume is ok, thanks for the advice
It works for windowslogon, but this is not the purpose
I want a music note played for several seconds, not just a beep, blabla, bing, bong or  boum
Thanks
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LeTay

ASKER

I tried, setting the duration to 5000 msec but on sndPlaySound (put a breakpoint), no sound comes out and it does not last for the 5 seconds (its immediately terminated)
Strange, because works to me (win7 + Delphi 6). You use win 10 and Delphi xx?
Avatar of LeTay

ASKER

Use Windows 7 and Delphi XE2
Code is unbelievably more complex than in the years 1970 !
I remember I coded entire music partition with text file input (notes, durations etc...) very simply
Shell I use .wav files instead ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LeTay

ASKER

Will try that ...
example: RiffId: string = 'RIFF'; goes to RiffId: AnsiString = 'RIFF';