Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Play Sound On Form Close ????? 1

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
NL
I want for my users to hear a sound when my application is
shut down. It's just a simple .wav. What I do is this.
I first assign the location of the .wav to the mediaplayer
named sound. Then I check if the file exists, if it exists,
the sound is played, otherwise nothing happens. Now this
works as a normal button click procedure but it doesnt under any of the forms events.

procedure TForm1.FormDestroy(Sender: TObject);
begin

Sound.FileName := 'C:\WINDOWS\MEDIA\LOGGOFF.WAV';
if FileExists(Sound.FileName) then
Sound.Play;

end;

your help is appreciated ;-)

;-) BobbaFet ;-)
Everyone has a right to my opinion.
E-mail me at cwcon@programmer.net
 
You have to Open the media first, and then wait to the clip to end before giving the control back to the application...

Try this in the OnClose event...

begin
Sound.FileName := 'C:\WINDOWS\MEDIA\NOTIFY.WAV';
if FileExists(Sound.FileName) then
begin
Sound.Open;
Sound.Wait := true;
Sound.Play;
Sound.Close;
end;
end;
 
Hi Nordlund,

I have autoopen set to true isn't that good enough???

BobbaFet Everyone has a right to my opinion.
E-mail me at cwcon@programmer.net
 
I haven't used the TMediaPlayer so much, but I've recently tested to use AutoOpen, with no luck... Sorry.




Andreas Nordlund
Software developer
 
I've done something similar by putting an invisible MediaPlayer on the form, looking for the file, setting the MediaPlayer FileName property, and putting the play code in the on form close.

MediaPlayer1.Play;

I had to set the DeviceType to "dtAutoSelect". Before I did this nothing would play.

hope this helps Mahalo,
cg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top