Click here to Skip to main content
Licence CPOL
First Posted 6 Mar 2006
Views 29,539
Downloads 711
Bookmarked 19 times

System.Media Sound

By | 6 Mar 2006 | Article
An article on System.Media and how to use simple sounds or *.wav in Windows form application
Sample Image - systemsound.jpg

Introduction

Prior to working with Visual Studio® 2005, adding even simple tunes and system sounds to your application was a challenge. There are numerous new classes and namespaces that have been added to the Microsoft® .NET Framework 2.0 to help you do just that. I'm going to take a look at one of them, the System.Media namespace.

Background

Use System.Media namespace for the following. I will be providing all the code snippets in C#.

    using System.Media;

Using the Code

Use the SystemSounds class to play system defined sounds. This class has five public properties which return an object of SystemSound. The properties are as follows:

  • Asterisk
  • Beep
  • Exclamation
  • Hand
  • Question

Now for playing a Beep sound, one can use the Play function exposed by the SystemSound class.

    //
    // To play a beep
    //
    SystemSounds.Beep.Play();

Use the SoundPlayer class to play wave sounds, be it from file, stream, a URL or an embedded WAV resource. Pass the path of the file/URL in the constructor and load the file asynchronously using the LoadAsync function. One should explicitly load the sound asynchronously if it is from a URL or a stream.

    sndPlayer = new SoundPlayer("http://localhost/test.wav");
    sndPlayer.LoadAsync();

History

  • 6th March, 2006: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

gfx_sikander

Web Developer

United States United States

Member

gfx_sikander aka sam aka Wicked_SuNny. call him by any of these names. Gfx is pusuing B.Tech in computer science and engineering at International institute of information technology hyderabad. Currently, he in 4th year and looking forward to explore .Net Technology and its competitors. He is programming since the age of 14. His area of interest are C++, ASP.Net, Game programming and Compter Networks. He likes to make web pages and flash animations. It must also be mentioned here that gfx does not usually speak about himself in the 3rd person. Smile | :)
 
visit his space to know more about him ...

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 6 Mar 2006
Article Copyright 2006 by gfx_sikander
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid