Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

How to: Play a Sound Embedded in a Resource from a Windows Form

You can use the SoundPlayer class to play a sound from an embedded resource.

private void playSoundFromResource(object sender, EventArgs e)
{
    System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
    System.IO.Stream s = a.GetManifestResourceStream("<AssemblyName>.chimes.wav");
    SoundPlayer player = new SoundPlayer(s);
    player.Play();
}

This example requires:

Importing the System.Media namespace.

Including the sound file as an embedded resource in your project.

Replacing "<AssemblyName>" with the name of the assembly in which the sound file is embedded. Do not include the ".dll" suffix.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.