Tag Archives: play wav

Play Audio Files with SoundPlayer Class

Here is simplest way to play Audio Files and System Sounds with SoundPlayer class in .Net

//Namespace:  System.Media
//Assembly:  System (in System.dll)

using System.Media;

// Create an instance of the SoundPlayer class and attaches the specified .wav file

SoundPlayer soundplayer= new SoundPlayer("audio file path");

// Load the .wav file.

//Check if loading of a .wav file has successfully completed.

if (soundplayer.IsLoadCompleted)

//plays the selected .wav file


// play system sounds

NOTE: The SoundPlayer class cannot play other file types, such as .wma or .mp3. If you want to play other file types, you can use the Windows Media Player control. For more information, see Using the Windows Media Player Control in a .NET Framework Solution and Windows Media Player Object Model Reference for Visual Basic .NET and C# in the Windows Media Player SDK.