设置任何应用程序的音量
我想知道如何在 C# 中设置特定应用程序(如任何正在运行的应用程序,而不仅仅是我自己的应用程序)的音量级别。
我知道我可能必须使用 P/invoke,这很好。我只是不确定声音 api 的工作原理以及如何获取/设置特定应用程序的音量(例如 vista/7 中的音量混合器)。
我知道可以通过编程方式进行,因为 nircmd 有一个功能可以做到这一点。
任何帮助将不胜感激,谢谢。
I was wondering how I could set a specific application (as in any running application, not just my own)'s volume level in c#.
I know I'd probably have to use P/invoke, this is fine. I'm just not sure on how the sound api's work and how I would go about getting/setting the volume of specific applications (like the volume mixer in vista/7 can).
I know it's possible to do programattically because nircmd has a feature that can do it.
Any help would be appriciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您应该查看此处。通过链接,您将找到用于操纵端点音量的接口和 API 函数。除了文档之外,Microsoft 还提供了一些 C++ 代码示例。正如您所说,使用平台调用可以在 .NET 中获得相同的功能。
I think you should look here. Following the links you'll find interfaces and API functions to use to manipulate endpoints' volume. Together with the documentation, Microsoft provided some code samples in C++. As you said, it is possible to get the same functionalities to work in .NET using platform invoke.
我认为(并希望)您的请求无论出于何种意图和目的都是不可能的。允许应用程序设置自己的音量就像允许应用程序覆盖用户的通知图标设置一样。这些设置是用户设置,因此您无法规避它们。
想象一下,用户设置了扬声器的音量,但调暗了所有单独应用程序的音量。您的应用程序出现了,并且“什么,我将自己设置为最大音量”。你刚刚让一个用户聋了,或者至少畏缩在房间的角落里,吓得要死。
I think (and hope) your request is, for all intents and purposes, impossible. Allowing an application to set its own volume is like allowing an application to override the user's notification icon settings. These settings are user settings, so you can't circumvent them.
Imagine for an instance that a user has the volume of his speakers set way up, but has dimmed the volumes of all individual applications. Your application comes along and goes 'whatevs, I'll just set myself to full volume'. You've just made a user go deaf, or at least cower in a corner of the room, scared to death.