I'm playing a game with some others coders. You get to write one oneline of C# and as many xaml lines as you want.
Anyone know how to play a sound in one line before the semi-colon;
This is as close as I can get so far
SoundPlayer simpleSound = new SoundPlayer(@"c:\Media\pacman.wav");
simpleSound.Play();
Edit: tried Blorgbeard's code, but sound isn't playing for some reason
if (Listbox.SelectedItem.ToString() == "2 Good 2 B True")
{
try
{
(new SoundPlayer(@"/Project;component/sounds/pacman.wav")).Play();
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
}
No need for a variable:
(new SoundPlayer(@"c:\Media\pacman.wav")).Play();
Blorgbeard's code works for me if I use PlaySync() instead of Play():
(new SoundPlayer(soundFile)).PlaySync();
Play() plays sound in another thread. This may be the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With