开发者

WPF (system)sounds don't work

开发者 https://www.devze.com 2023-03-29 17:59 出处:网络
I have the following problem: I just want to play a short sound but I hear nothing. The soundfile\'s property \"Copy to output directory\" says \"Copy always\".

I have the following problem: I just want to play a short sound but I hear nothing. The soundfile's property "Copy to output directory" says "Copy always". Strangely when I copy a existing and working example nothing happens but the original works. I can't find my problem.

Additionally systemsound don't work either.

Any ideas?

Thank you!!

using System.Media;
using System.Windows.Input;
using Microsoft.Windows.Controls.Ribbon;

namespace WpfRibbonApplication14
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : RibbonWindow
    {
        SoundPlayer player = new SoundPlayer("sound.wav");

        public MainWindow()
        {
            InitializeComponent();
            player.LoadAsync();

            // Insert code required on object creation below 开发者_如何学JAVAthis point.
        }

        private void Button1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            player.Play();
        }
    }
}


Check that your Button1_MouseLeftButtonDown event handler was actually hooked up in your MainWindow.xaml to Button1's click event, e.g.: <Button Name="Button1" Click="Button1_MouseLeftButtonDown" />

PS: I came here expecting this question to be unanswered, but it had actually been answered in the comments, so I'm reposting the answer here. I am not trying to steal Hans Passant's rep, honest!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号