Hi
System.Media Namespace provides many classes to work with the
Sound in the application. One of the important classes to play sound is SoundPlayer
class. With the help of this class we can simply WAV Files.
The wave files can be loaded by using either the file path,
The URL or a stream that contains the .wav file. We can also use an embedded
resource that has the .Wav file.
For providing the location of the Sound file we have to use
the soundLoaction
and the stream
property of the SoundPlayer class. The soundLoaction property takes
either the file path or the URL of the sound to be loaded. The stream
property takes the name of the stream based Object containing the (.Wav)
audio to load.
We use the SoundPlayer.Play() method to play the sound.
You can play audio content .wav files synchronously or
asynchronously. Calling the Play method asynchronously plays the audio content on a
separate thread so your code can continue executing. PlaySync, on the other
hand, will play the audio content synchronously and pause program execution
until the playback has completed. PlayLooping works the same as Play, but as
the name suggest it goes on playing the sound in a loop until the stop method
is called to stop the play back.
Here is the code to do the Job
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
Stream SoundResource;
SoundResource = MyApplication.Properties.Resources.DING;
player.Stream = SoundResource;
player.Play();
Here I am loading the Wav from a stream. I have already add
the wav file to the resource manager. Now I am picking up the resource into a
stream and playing the sound.
Hope this helps
Thanks
Vikram