6 6 Votes

Delphi: Play System-Sounds

Tutorial by Delphian | 29/06/2012 at 15:33

Delphi makes it very easy to play system sounds like the start-up tone, the end-sound or the standard error sound within your own application.

We are using the PlaySound function from the unit MMSystem for this, with which it is possible to play any wave file. We can pass to PlaySound a file or the name of a system sound as well as information about how the sound should be played:

uses MMSystem;
 
PlaySound('SYSTEMSTART', 0, SND_ASYNC);

The example plays the Windows start-up tone (constant SYSTEMSTART) for a single time (SND_ASYNC).

Constants for System Sounds

Instead of "SYSTEMSTART" we can use the following other constants with PlaySound:

  • SYSTEMEXCLAMATION (Note)
  • SYSTEMHAND (Critical Stop)
  • SYSTEMQUESTION (Question)
  • SYSTEMSTART (Windows-Start)
  • SYSTEMEXIT (Windows-Shutdown)
  • SYSTEMASTERIX (Star)
  • RESTOREUP (Enlarge)
  • RESTOREDOWN (Shrink)
  • MENUCOMMAND (Menu)
  • MENUPOPUP (Pop-Up)
  • MAXIMIZE (Maximize)
  • MINIMIZE (Minimize)
  • MAILBEEP (New Mail)
  • OPEN (Open Application)
  • CLOSE (Close Application)
  • APPGPFAULT (Program Error)

All available constants are defined in the registry under the path HKEY_CURRENT_USER -> AppEvents -> Schemes -> Apps -> .Default. Here, depending on the installed applications and your Windows version, you can surely find the one or another sound file and the associated constant.

Playback Modes

SND_ASYNC plays the sound in the background and let the program continue while playing.

SND_SYNC stops the program while playing and lets the program continue only after playing the sound completely.

SND_LOOP plays the sound in a loop over and over. Only when playing a new sound, or when you call PlaySound (nil, 0, 0) the playing is stopped.

ReplyPositiveNegative

About the Author

Avatar AuthorThe author has not added a short description to his profile yet.
Show Profile | Message

 

Related Topics

Android Audio Recorder
Open Question | 5 Answers

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own articles on askingbox.com. How to do.