How do I play default Windows sounds?

How do I play default Windows sounds?

Rate This
  • Comments 6

Sometimes, you might want to make your application a bit more audible. If you are using .NET 2.0, you can utilize the new System.Media namespace and its SystemSound and SystemSounds classes.

The SystemSounds class contains five static properties that you can use to retrieve instances of the SystemSound class. This class in turn contains the Play() method, which you can use to play the wave file associated with the sound in Windows Control Panel. Note that the user can also disable all sounds altogether, which would mean that no sound can be heard through the computer speakers.

To play for example the classical beep sound, you could use the following code:

System.Media.SystemSounds.Beep.Play();

Similarly, you could play the “Question” sound with this code:

System.Media.SystemSounds.Question.Play();

The System.Media namespace is defined in System.dll, so there are no new DLLs you would need to add to your project’s references to use the above code.

[author: Jani Järvinen, C# MVP]

Leave a Comment
  • Please add 8 and 7 and type the answer here:
  • Post
  • Easy Notifications with System.Media.SystemSounds

  • PingBack from http://blog.f9group.com/technology/c/how-do-i-play-default-windows-sounds/

  • Hi. I know this article is old, but very helpful. Thanks for all!!

  • Is system.media  in vs2023 for windows phone expree

  • thank you

    i didn't know it could be that much easy.

  • plz tell me when i take my computer it having a system speaker and it play music everything but when i do new window the system sound did not work and did not play any sound like music and everything but headphone and speaker is working but system sound did not work plzzzzz solve my problem plzzzzzzzzzzzzzzz

Page 1 of 1 (6 items)