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
How to Pass Anonymous Types as Parameters
Why/When Would It Be Appropriate to Override Tostring
Better Way to Query a Page of Data and Get Total Count in Entity Framework 4.1
Editorfor() and HTML Properties
Upload Files and JSON in ASP.NET Core Web API
How to Initialize a C# Dictionary with Values
How to Get the Full Url of the Page I am on in C#
Why Func<T,Bool> Instead of Predicate<T>
What's the Difference Between Returning Void and Returning a Task
The Current Synchronizationcontext May Not Be Used as a Taskscheduler
How to Include Quotes in a String
How to Get the Last Five Characters of a String Using Substring() in C#
How to Execute Task in the Wpf Background While Able to Provide Report and Allow Cancellation