Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add notification sound file to exe in c#

I'm trying to add a notification alarm when a user presses a button

    private void button1_Click(object sender, EventArgs e)
    {
        SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\.........\ambbrdg7.wav");
        simpleSound.Play();
    }

I want to add the ambbrdg7.wav to my exe file to make sure my program always has access to this file

like image 527
motaz99 Avatar asked Nov 22 '25 16:11

motaz99


2 Answers

Project + Properties, Resources tab, click on the arrow on the "Add Resource" button and select your .wav file. Then it is simply:

var player = new System.Media.SoundPlayer();
player.Stream = Properties.Resources.tada;
player.Play();

where "tada.wav" was the resource I added, change it to your resource name.

like image 176
Hans Passant Avatar answered Nov 25 '25 05:11

Hans Passant


You either want to add the file as Content (add the file to your project and set it as Build Action -> Content) or add it as a resource - see http://msdn.microsoft.com/en-us/library/7k989cfy(v=vs.80).aspx

like image 36
Adam Baxter Avatar answered Nov 25 '25 06:11

Adam Baxter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!