RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: .NET
Expertise: Advanced
Jun 8, 2009

Getting Better Sound Capabilities in .NET 3.0

The .NET Framework includes a SoundPlayer class (in System.Media) that can play sound files. However, this class suffers from two crippling limitations: it can play only PCM-encoded WAV files, and it can play only one sound at a time. For example, if you start playing a long sound, and then try to add a second sound, the first one will stop so the second one can start. This limitation makes it unusable for sound effects in games.

Fortunately, .NET 3.0 includes a new class called MediaPlayer that solves some of these problems. The MediaPlayer class can play any sound playable by the full Windows Media Player (including WAV, MP3, etc.) and it can play multiple sounds simultaneously. The only downside to the MediaPlayer class is that it cannot play a sound from a stream (e.g., if it's embedded within the .exe file)—it can play only ordinary files from disk.

Laks Schabse
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date