Reputation: 22571
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?
Upvotes: 4
Views: 3990
Reputation: 16142
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.
Upvotes: 3
Reputation: 1722
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.
Upvotes: 1