专门更改当前应用程序的音量

发布于 2024-10-09 05:37:12 字数 762 浏览 0 评论 0原文

从 Windows Vista 开始,waveOutSetVolume 函数 (winmm.dll) 不再在操作系统主卷上运行,而是单独针对每个应用程序运行。默认情况下,它设置为 100%,这意味着应用程序以与操作系统相同的音量播放声音。

现在我想利用这种效果:仅更改当前应用程序的音量而不更改操作系统音量。

我尝试了 http://www.geekpedia 提供的应用程序.com/tutorial176_Get-and-set-the-wave-sound-volume.html。我添加了一个 WindowsMediaPlayer 控件,并使用 URL 属性(自动启动设置为 true)将 Webradio 流加载到其中。乍一看,代码并没有达到应有的效果:当我滚动滑块时,收音机会继续以相同的音量播放,即使我设置为 0(相当于将其静音)。我调试了一下,发现一切正常,waveOutSetVolume 返回 0。那应该没问题,还是我弄错了?

我打开了 Windows 7 提供的混音器控制台。在那里我看到了以下内容: 当我滚动示例中的滑块时,混音器视图中相应应用程序的滑块会发生变化(理应如此)。但音量没有改变。但是,如果我在混音器控制台中降低应用程序的音量(使用鼠标手动),则网络广播会以较低的声音播放(正如它应该的那样)。似乎在我的代码中缺少一些“提交”调用来实际使操作系统相应地调整应用程序的音量。

有什么想法吗?谢谢,大卫

from Windows Vista on, the waveOutSetVolume function (winmm.dll) no more operates on the OS master volume but for each app individually. As a default it is set to 100% which means that the app plays sound with the same volume like the OS.

Now I want to make use of exactly this effect: Only changing the volume for my current app without changing the OS volume.

I tried the app provided at http://www.geekpedia.com/tutorial176_Get-and-set-the-wave-sound-volume.html. I added a WindowsMediaPlayer control and loaded an Webradio stream into it using the URL property (autostart set to true). At first glance the code does not what it should: When I scroll the slider the radio keeps on playing at the same volume, even if I set to to 0 which would equal muting it. I debugged and figured that everything is ok, waveOutSetVolume returns 0. That should be ok, or am I mistaken?

I opened the mixer console provided by Windows 7. There I saw the following: The slider of the respective app in the mixer view changes (as it should) when I scroll the slider in the sample. Yet the volume doesn't change. But if I reduce the app's volume in the mixer console (manually with my mouse), the webradio plays in a lower voice (as it should). It seem's that in my code there is missing some "Submit" call to actually make the OS adjust the app's volume accordingly.

Any ideas? Thanks, David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你曾走过我的故事 2024-10-16 05:37:12

您可以使用音频会话 API IAudioVolume 和 IAudioSessionNotification 修改当前应用程序音量并使用应用程序中的音量滑块跟踪您的音量。

You can use the Audio session APIs IAudioVolume and IAudioSessionNotification to modify the current apps volume and to track your volume with the volume slider in the app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文