I am developing a screen recording software and it has volume control. The code I pasted below is how I am controlling the volume.
static class NativeMethods
{
[DllImport("winmm.dll")]
public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
[DllImport("winmm.dll", EntryPoint = "waveOutSetVolume")]
public static extern int WaveOutSetVolume(IntPtr hwo, uint dwVolume);
[DllImport("winmm.dll", SetLastError = true)]
public static extern bool PlaySound(string pszSound, IntPtr hmod, uint fdwSound);
}
//Event for handling volume control
private void VolumeSlider(object sender, RoutedPropertyChangedEventArgs<double> e)
{
// Calculate the volume that's being set
int NewVolume = ((ushort.MaxValue / 10) * (int)slider.Value);
// Set the same volume for both the left and the right channels
uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
// Set the volume
NativeMethods.WaveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
}
By viewing the Volume Mixer on Windows I can see this sets the application's volume and not the device. This is great because only changing the application's volume will change the volume of the video it's recording.
Now I want to know if it is possible to create a VU Meter for the application's volume like the one in Windows Volume Mixer. I have tried to achieve this effect using NAudio, but I'm not sure how or if it can. I am open to other APIs.
EDIT: I am not asking how to change the volume...I just need a functioning VU Meter like the on in the Mixer.