当用户从我的程序收到通知时如何播放自定义声音 [英] How to play a custom sound when user gets a notification from my program

查看:69
本文介绍了当用户从我的程序收到通知时如何播放自定义声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用vb .net创建了一个应用程序,该应用程序指示大写锁定和数字锁定状态.应用程序发送 锁定状态更改时,会气球通知.您可能知道从应用程序发送通知时,系统会播放默认的通知声音.我想为我的应用程序更改声音.我的意思是我有任何代码 可以在我的应用程序中使用,以使该应用程序在通知过程中播放自定义声音(来自.wav文件)而不是默认声音?

I've created an application using vb .net that indicates caps lock and num lock status. The application sends Baloon notifications whenever the lock state changes. You may know that the system plays a default notification sound when a notification is sent from an application. I want to change the sound for my application. I mean is there any code I can use in my application that enables the application to play a custom sound (from a .wav file) instead of the default sound during the notification?

Private Sub kbHook_KeyDown(ByVal Key As System.Windows.Forms.Keys) Handles kbHook.KeyDown


If Key = Keys.CapsLock Then
            If My.Computer.Keyboard.CapsLock = False Then
                ButtonToggleCaps.BackgroundImage = My.Resources.CustButton2

            NotifyIconCaps.Icon = My.Resources.TrayIcon_Lime_Caps_Off
            NotifyIconCaps.ShowBalloonTip(500)
            NotifyIconCaps.BalloonTipText = "Caps Lock OFF"
            ShowInTaskbar = False

        ElseIf My.Computer.Keyboard.CapsLock = True Then
            ButtonToggleCaps.BackgroundImage = My.Resources.CustButton1

            NotifyIconCaps.Icon = My.Resources.TrayIcon_Lime_Caps_On
            NotifyIconCaps.ShowBalloonTip(500)
            NotifyIconCaps.BalloonTipText = "Caps Lock ON"
            ShowInTaskbar = False
            End If
        End If
        End Sub


如果无法更改默认通知声音,我们是否至少可以禁用默认声音,以便我的应用程序可以在显示通知时播放自定义声音?


If it is not possible to change the default notification sound, can we at least disable the default sound so that my application can play a custom sound whenever the notification is displayed?

推荐答案

好吧,如果您希望仅在您的应用程序中发生这种情况,那么最简单的方法可能是在播放音频.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.


这篇关于当用户从我的程序收到通知时如何播放自定义声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆