I want to find the current system volume and set the volume of my app inside the volume mixer but it seems that everything I find:
- Can change the system volume (one problem sorted)
- Cannot change the application volume
- Or simply doesn't work at all
- And so far, nothing at all can manage to GET me the system volume
We are currently using nircmd to set the global volume and that works great but it doesn't seem to have an option to GET the current volume so we can later restore the volume to what it was. As for setting the value of the app itself, rather than the global volume, I have been hunting down every thread I can find and everything (on here as well as elsewhere) all lead me to either C++ documentation or to C# wrappers around that library but that code simply doesn't work due to that invalid cast right at the root of every function.
Here is one such an example of the broken code from right here on stackoverflow: Controlling Volume Mixer
All those libs/code samples I found do this at some point:
private static ISimpleAudioVolume GetVolumeObject(int pid)
{
IMMDeviceEnumerator deviceEnumerator =
(IMMDeviceEnumerator)(new MMDeviceEnumerator());
This gives an invalid cast problem due to this:
internal class MMDeviceEnumerator
{
}
internal interface IMMDeviceEnumerator
{
}
The class it is trying to cast to does not implement the interface and apparently thus the cast is not valid. I tried to manually add the functions to MAKE it implement the interface but since that is simply a hack it causes other errors down the line and is not a viable option.
Besides, since absolutely every code snippet or lib I have found on here or elsewhere does this exact same thing it seems unlikely that such a change would have gone unnoticed. Since all the code is many years old, can I assume that this simply doesn't work in Win10?
If so, then how can I do those two things I mentioned?
- Find the current system volume and
- Set the current application's volume per attached hardware device?
I also tried fetching the app process for SndVol.exe and successfully find it (or open it if it's not running) but once I have the handle for the mixer I have no idea what to do with it. Is it possible to send commands to the application via the input override available through the Process class? I am totally inexperienced with the Process class so forgive me if that question sounds stupid.
EDIT: My question is simply this: How can I change the individual sliders inside Volume Mixer using.NET. For some reason people are reading this as "How to use Unity?". For that reason I want to pose my question another way that will hopefully make it sound less "esoteric magic" and more "general use case" (hopefully)... :P
Say I wanted to detect the systems' attached audio devices and add a drop down to my app listing those devices, If I then wanted to add a volume slider for each running app so I could adjust the app's volume for that particular device from within my own app, exactly like Volume Mixer does... how would I go about implementing that?
More specifically, the thing i want to know is how do I get my slider values applied to the individual application's volume for the selected device?