gpt4 book ai didi

c# - WPF(系统)声音不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 14:13:15 24 4
gpt4 key购买 nike

我有以下问题:我只想播放一段短促的声音,但我什么也没听到。声音文件的属性“复制到输出目录”表示“始终复制”。奇怪的是,当我复制一个现有的和工作的例子时,除了原始作品之外什么都没有发生。我找不到我的问题。

此外,systemsound 也不起作用。

有什么想法吗?

谢谢!!

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 this point.
}

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

最佳答案

检查您的 Button1_MouseLeftButtonDown事件处理程序实际上在您的 MainWindow.xaml 中连接到 Button1 的单击事件,例如:<Button Name="Button1" Click="Button1_MouseLeftButtonDown" />

PS:我是来这里期待这个问题没有答案的,但实际上已经在评论中回答了,所以我在这里重新发布答案。我不是想偷Hans Passant's代表,诚实!

关于c# - WPF(系统)声音不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7153399/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com