Saturday, June 9, 2007

Playing wav file using C#.NET 2.0.

Playing wav file using C#.NET 2.0.
==================================

The below code is self explainatory.

public void playWavFile() {
System.Media.SoundPlayer wavPlayer = new System.Media.SoundPlayer();
wavPlayer.SoundLocation = @"c:\click.wav";
wavPlayer.Play();
}


Also you can play some system sounds

public void playSystemSounds() {
SystemSounds.Beep.Play();
SystemSounds.Asterisk.Play();
SystemSounds.Exclamation.Play();
SystemSounds.Hand.Play();
SystemSounds.Question.Play();
}



Also the sound related classes include:

Microsoft.VisualBasic.Devices.Audio.Play Method
System.Media.SoundPlayer Class
System.Media.SoundPlayer.Play Method
System.Media.SoundPlayer.PlayLooping Method
System.Media.SoundPlayer.PlaySyncMethod

No comments: