private void btnMeow_Click(object sender, EventArgs e) { using (SoundPlayer player = new SoundPlayer( Properties.Resources.Meow)) { player.Play(); } }
The code creates a SoundPlayer, passing its constructor the audio resource. The SoundPlayer class is in the System.Media namespace so the program includes a using statement to make creating the SoundPlayer easier.
When it has finished using the SoundPlayer, the program should call its Dispose method so the code creates it in a using statement to make that easier.
After creating the object, the code simply calls its Play method. The SoundPlayer does the rest.
Comments