如何忽略我的应用程序的声音?

编程入门 行业动态 更新时间:2024-10-10 19:16:34
本文介绍了如何忽略我的应用程序的声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我也有声音的应用程序。我有一个全球性的属性,静音。问题是,有这么多不同的事情,它可以使声音,我不想通过不同的类类型和静音/取消静音他们的声音进行迭代。相反,我正在寻找一种方式来静音在全球应用水平的声音。我不是说无论是静音整个系统的体积。

I have an application which has sound. I have a global property to mute the sound. The problem is, there's so many different things which can make sound, I would hate to iterate through different class types and mute/unmute their sound. Instead, I'm looking for a way to mute the sound on a global application level. I don't mean muting the entire system volume either.

一情形:在Windows 7中,你可以打开音量合成器,调整各个应用程序的音量。虽然我不打算改变这一实际特定值(因为我知道这是Windows 7中特定的),我想一下子改变一切的量我的应用程序。我还需要完全静音一切的声音在我的应用程序的能力。我需要这种能力是与Windows XP以上兼容。我假定这将涉及Windows API调用,但我不知道什么叫做。

One scenario: In Windows 7, you can open the Volume Mixer and adjust the volume of individual applications. While I don't intend to change this actual particular value (as I know it's Windows 7 specific), I would like to change the volume of everything in my application all at once. I would also need the ability to completely mute the sound of everything in my application. I need this ability to be compatible with Windows XP and above. I am assuming it will involve Windows API calls, but I have no idea what calls to make.

推荐答案

什么你要求的是不能在XP;操作系统根本不支持每个应用程序的音量。

What you're asking for isn't possible on XP; the OS simply does not support per-application volume levels.

您可以完成你想要创建一个设置类,使事情变得像 SoundActive:布尔或 PlaySounds:布尔或类似的东西。将其放置在它自己的单位,有一个创建它的实例,并且释放它最终确定部分(使它有效的全球值的集合)初始化节。

You can accomplish what you want by creating a settings class that keeps things like SoundActive: Boolean or PlaySounds: Boolean or something similar. Place it in it's own unit, and have an initialization section that creates an instance of it and a finalization section that frees it (making it effectively a collection of global values).

每个需要这些设置接入单元只需使用包含它们的单元,并相应地调整行为。因此,每个子类或形式或任何的将只需要一个检查又说:

Each unit that needs access to these settings simply uses the unit containing them, and adjusts behavior accordingly. So each of your child classes or forms or whatever would just need a check added:

if CurrentSettings.PlaySounds then // Code that makes sounds, plays music, whatever.

设置类也可以包含跟踪当前的音量水平(XP系统,全系统级)的方法,以及增加或使用降低音量的 MMSYSTEM 音量功能(有吨的位置,并通过这样的谷歌的例子)。然后,您的应用程序可以使用 OnActivate 和 OnDeactivate 事件来设置音量,当你的应用程序获得焦点,并恢复它当你的应用程序失去焦点适当的音量。

The settings class can also contain methods that keep track of the current volume level (on XP, the system-wide level), and methods to increase or decrease volume using the MMSystem volume functions (there are tons of examples here and through Google of doing so). Your app can then use the OnActivate and OnDeactivate events to set the volume level when your app gains focus, and restore it to the proper volume when your app loses focus.

在Vista和更高版本,您可以使用 IAudioEndPointVolume 接口我前面提到的,要么在 GetMasterVolumeLevel 或 SetMasterVolumeLevel 的方法来控制系统范围体积(我有这样的一个例子,用适当 MMDevAPI 接口定义一起)或设备级音量(使用的 IMMDevioce.Activate 来,然后再上面在 ppInterface 参数从 IMMDevice.Activate 接收设备接口)上IAudioEndPointVolume 方法。

In Vista and higher, you can use the IAudioEndPointVolume interface I mentioned earlier and either the GetMasterVolumeLevel or SetMasterVolumeLevel methods to control system wide volume (I have an example of doing this, along with the appropriate MMDevAPI interface definitions) or device level volume (using IMMDevioce.Activate to select the proper device first and then the above IAudioEndPointVolume methods on the device interface received from IMMDevice.Activate in the ppInterface parameter).

有关单个应用程序,您使用 ISimpleAudioVolume 接口,它有四种方法: GetMasterVolume 和 SetMasterVolume ,其中控制音量为您的应用的音频会话水平, GetMute 和 SetMute 来让你获取当前静音标志值或将其设置分别。 (MS的拉里·奥斯特曼,谁是谁的在Vista和Win7的新的音频支持工作的开发者之一,有着极大的在他的关于新的API以及何时使用他们每个人的类型的音频博客起点文章。)

For individual applications, you use the ISimpleAudioVolume interface, which has four methods: GetMasterVolume and SetMasterVolume, which control the volume level for your application's audio session, and GetMute and SetMute to allow you to retrieve the current mute flag value or set it respectively. (Larry Osterman of MS, who was one of the developers who worked on the new audio support in Vista and Win7, has a great starting point article on his blog about the types of audio in the new API and when to use each of them.)

这是理论上可行,以确定您所使用的操作系统运行,并使用在XP的 MMSYSTEM 功能之间的程序中切换和更早版本,而 MMDevAPI 的功能和更高的。在这里希望有人这样做提供code是有点不合理,但是。我提供的链接应该让你在正确的轨道上开始了,当你碰上沿途的具体帮助碰壁通过这些断枝的工作将是巨大的问题。

It's conceptually possible to determine at runtime which operating system you're using, and to programmatically switch between using the MMSystem functionality on XP and earlier, and the MMDevAPI functionality on Vista and higher. Expecting someone here to provide the code for doing so is a little unreasonable, however. The links I've provided should get you started on the right track, and when you run into snags along the way specific help in working through those snags would be great questions.

更多推荐

如何忽略我的应用程序的声音?

本文发布于:2023-11-12 13:28:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   声音

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!