Andrej Tozon's blog

In the Attic

NAVIGATION - SEARCH

Make some noise!

The .NET Framework 2.0 finally makes it very easy for your application to play some funky music. First, there's the SystemSounds class, allowing you to play basic, ehm, system sounds like Beep, Exclamation, Question, ... For example: SystemSounds.Asterisk.Play() plays the sound you have selected for the Asterisk event in your active sound scheme.

A bit more interesting is a SoundPlayer class, which lets you choose a custom .wav file to play:

SoundPlayer player = new SoundPlayer(@"c:\Windows\Media\Windows XP Startup.wav");
player.Play();

SoundPlayer lets you load the and play .wav files from a valid URL or a Stream object, in a synchronous or asynchronous manner. And if you really want to annoy your users, then PlayLooping() method is all what you need.