Get an audio session's volume level

孤街浪徒 提交于 2021-02-07 09:23:19

问题


Does anyone know how to get the current volume level of an audio session* in Vista or 7?

I've got the IAudioSessionControl2 and IAudioSessionManager2 instances you need to listen for volume changes, but actually getting the current volume is proving elusive.

*by audio session I mean (roughly) the per-application audio control, not the "master" one


Note that (so far as I can tell) IAudioSessionManager2->GetSimpleVolume() isn't the right answer here. The only thing that publishes a GUID in IAudioSessionControl2 is the Grouping parameter, and using it in GetSimpleVolume creates new sessions rather than giving you the control for an existing one.

GetSimpleVolume() is what I want, but where are the params coming from in this setup?


回答1:


Actually IAudioSessionManager::GetSimpleAudioVolume IS what you're looking for.

An audio session is identified by two (or three) things: The session guid, the process ID and the cross process flag (if the cross process flag is specified when the stream is created, the process ID is ignored).

The simple audio volume controls the volume of all the streams within that audio session. It's fairly straightforward (most rendering frameworks specify NULL for the session GUID). If your application uses a specific session GUID, you should just specify the session GUID your application is using.

There's one other twist though. The volume control (sndvol.exe) combines all sessions with the same "grouping param" together in the UI - this isn't a part of the volume control, it's a UI convenience feature that exists only for web browsers like IE - it exists to allow 3rd party audio frameworks (which specify a GUID_NULL session GUID) and the WMP OCX (which specifies a cross process session with a specific session GUID) to share a single slider in the volume UI.




回答2:


I think the ISimpleAudioVolume interface should do what you need.
It has a method called GetMasterVolume witch returns the volume for the audio session.
To obtain the interface you can call IAudioSessionManager::GetSimpleAudioVolume.

For the guid parameter you can use the one you specify when creating the audio streams with IAudioClient::Initialize. I honestly don't know if there are other ways to get the guid for a session.

The grouping parameter is the id of the group to witch the session belongs and not an id of a session.



来源:https://stackoverflow.com/questions/1128945/get-an-audio-sessions-volume-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!