Posts tagged ‘wav’

C# Embed wave file

Here is a simple way to embed wav file or any other resource in a C# application. Just add the file and set it’s property “Build Action” to “Embedded Resource”. Then at run time extract the resource and use it in your application.

// this will show you all available resource
//string[] resNames = a.GetManifestResourceNames();

// extract the wav file
Stream mstrWaveFile = Assembly.GetExecutingAssembly().GetManifestResourceStream(WAVE_RESOURCE);
SoundPlayer player = new SoundPlayer(mstrWaveFile);
// and play it
player.Play();