且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当用户从我的程序收到通知时如何播放自定义声音

更新时间:2021-09-07 00:37:30

好吧,如果您希望仅在您的应用程序中发生这种情况,那么最简单的方法可能是在播放音频.Wav文件之前先静音然后取消系统声音静音或将其音量设置为零.然后取消系统声音静音或将其音量调回 到曾经执行过的状态.这样其他应用程序仍然可以使用系统声音.并且在您的应用出口上,确保系统声音未静音或将音量设置回原来的水平.

Well if you want this to only occur for your application then the simplest method may be to mute then unmute the systems sounds or set its volume to zero prior to playing your audio .Wav file. Then unmute the system sounds or set its volume back to what it was once that is performed. Such that other apps still can use sytem sounds. And on your app exit make sure system sounds is unmuted or the volume level is set back to what it was.

您还将用于声音的.Wav文件作为资源嵌入到您的应用程序中,因此它们是可执行文件的一部分,还是打算从需要磁盘IO加载磁盘的文件中播放文件,然后再播放这些文件,这会花费一些时间?你打算怎么玩 他们一起?

Also are the .Wav files you use for sounds embedded as resources in your app so they are part of the executable or do you plan to play them from disk requiring disk IO to load the files prior to them playing which takes time? And what do you plan to play them with? The SoundPlayer Class can play a resource stream (My.Resources.SomeWavFilepreviouslyloadedtoyourappsresources) I believe and from a file I suppose.

正如您在下面的Volume Mixer中看到的那样,您可以使各种东西静音.我使用NotifyIcon编写了一个应用程序,基本上使用您的代码进行了模拟,但没有播放系统声音.这可能是因为我没有正确设置控制面板来播放系统声音 尽管如果某个应用被最大化以播放某种类型的提示音,我确实可以使它正常工作.并将应用程序",系统声音"设置为零或单独将其静音会使我最大化应用程序时听不到声音.

As you can see below in Volume Mixer you can mute various things. I wrote an app using NotifyIcon and basically used your code to simulate but no system sounds played. Which could be because I do not have control panel set correctly to play a system sound although I did get it to work for if an app was Maximized to play a beep of some type. And setting Applications, System Sounds to zero or muting it alone caused the sound not to be heard when I maximized an app.

我不知道如何仅以编程方式将音量设置为零或仅使应用程序",系统声音"静音.这是Win7.我不知道您使用的是什么操作系统,或者以下功能是否与您的操作系统相同.

I do not know exactly how to only programmatically set the volume to zero or mute just the Applications, System Sounds. And this is Win7. I don't know what OS you use or if the below feature is the same for your OS.