从 Windows 选择声音并播放它们
我有一个 WinForms 应用程序。该应用程序有一个“首选项”部分,用户可以在其中选择显示警报时播放哪些声音。
是否可以有一个组合框,用户可以从 Windows 存储的声音中进行选择,例如“紧急停止”、“紧急蜂鸣”等。这些可以在“控制面板”>>中找到。 “声音和警报”部分。
是否也可以有一个播放按钮来测试声音?
I have a WinForms app. This app has a Preferences section where the user will be able to select which sounds are played when an alert is being displayed.
Is it possible to have a combobox where the user can select from the Windows stored sounds such as "critical stop", "critical beep" and so on. These are found in the "Control Panel" >> "Sounds and Alerts" section.
Is it also possible to have a play button to test the sounds out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您不需要任何 API 来播放系统声音,只需编写如下代码:
SystemSounds
类包含以下预定义的系统声音:所有其他声音都要求您从注册表中读取所需的声音并使用如下代码播放它:
You do not require any API to play system sounds just write code like this:
The
SystemSounds
class contains the following predefined system sounds:All other sounds require you read the desired sound from the registry and play it with code like this:
试试这个:
Try this:
当然!您正在寻找的所有声音都可以通过
System.Media.SystemSounds
类,它们在其中公开为 与触发声音的事件类型相对应的公共属性。此外,
SystemSound
类< /a> 提供播放
方法,您可以调用该方法来异步播放该声音。例如,要播放“Critical Stop”声音,您只需编写以下代码:
Sure! All the sounds you're looking for are available through the
System.Media.SystemSounds
class, where they are exposed as public properties corresponding to the event types that trigger the sounds.Additionally, objects of the
SystemSound
class provide aPlay
method that you can call to play that sound asynchronously.So for example, to play the "Critical Stop" sound, you would simply write the following code:
SystemSounds
仅涵盖几声声音。要玩其他游戏,您需要阅读注册表:SystemSounds
only cover a few sounds. For playing the others, you need to read the registry :