Getting Individual Windows Application Current Volume Output Level as Visualized in Audio Mixer

Getting individual windows application current volume output level as visualized in audio Mixer

You can use CSCore.
There is a wrapper for the CoreAudioAPI-Audiosessions. Use something like that (for more details take a look at the unittests: AudioSession-UnitTests):

private static void Main(string[] args)
{
using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render))
{
using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
{
foreach (var session in sessionEnumerator)
{
using (var audioMeterInformation = session.QueryInterface<AudioMeterInformation>())
{
Console.WriteLine(audioMeterInformation.GetPeakValue());
}
}
}
}

Console.ReadKey();
}

private static AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
{
using (var enumerator = new MMDeviceEnumerator())
{
using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia))
{
Debug.WriteLine("DefaultDevice: " + device.FriendlyName);
var sessionManager = AudioSessionManager2.FromMMDevice(device);
return sessionManager;
}
}
}

To control an applications volume, take a look at the unit-tests here.

Reading the value of the volume in the windows mixer

Each item in the audio mixer (Sndvol) is a single audio session. Here's a great read from MSDN about how the sessions work in the background.

With that out of the way, you'll need to subscribe to audio session events to be notified of the following events:

  • The master volume level or muting state of the session submix has changed.
  • The volume level of one or more channels of the session submix has changed.
  • The session has been disconnected.
  • The activity state of the session has changed to active, inactive, or expired.
  • The session has been assigned a new grouping parameter.
  • A user-interface property of the session (icon or display name) has changed.

Directly copied from here.

Core Audio APIs are part of the Windows SDK, so you need to use P/Invoke to actually call that code. I think there are some .NET wrappers for the Core Audio APIs, and it should be easy to find them with a simple search.

Edit: Here's a good start for what you're trying to do. It includes code for managing the session sound. I didn't give it a thorough look, so I'm not sure if it has the session events implemented.

Retrieve current mixer levels with WMI?

Nope - none of the audio controls are exposed through WMI.



Related Topics



Leave a reply



Submit