wpfresourcessoundplayer

How to add sound in sound player from resource WPF


How can i add this sound image

like i make it with background in xaml.

<Controls:FlipView.Background>
                <ImageBrush ImageSource="Gamedata/MainMenuBackground.jpg"/>
            </Controls:FlipView.Background>

I already have tried this , but it didn't help

SoundPlayer PlaySound = new SoundPlayer(@"pack://application:,,,/Gamedata/Sounds/MenuClick.wav");
        PlaySound.Load();

Solution

  • I'm not sure what exactly you're trying to accomplish, but to play a sound with the SoundPlayer class you use the Play() method. To load it from a resource, add it to your Resources.resx file and use Properties.Resources.resourceName.

    SoundPlayer PlaySound = new SoundPlayer(Properties.Resources.MenuClick);
    PlaySound.Play();