I got this code to mute/unmute the master volume
private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
private const int WM_APPCOMMAND = 0x319;
[DllImport(\"u
I could not do it for all Windows versions (xp, vista & 7).
Though, I achieved it by used external programs, such as NirCmd, and sent the command I needed.
not so good solution but it did solve my problem.
This thread shows how to control the master volume from C#.
You might also be interested in the responses to this question: Get Master Sound Volume in c#
Especially the NAudio managed wrapper.
Have a look at this project http://www.codeproject.com/KB/vista/CoreAudio.aspx
They created an own mixer control, that also reports the current volumne and the mute/unmute state:
defaultDevice.AudioEndpointVolume.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(
AudioEndpointVolume_OnVolumeNotification);
// .. snip ..
void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data)
{
Console.WriteLine("New Volume {0}", data.MasterVolume);
Console.WriteLine("Muted {0}", data.Muted);
}
Does this help you?
EDIT: With this code and the class from the project you should be able to set and unset mute directly (without toggle):
MMDeviceEnumerator devEnum = new MMDeviceEnumerator();
MMDevice defaultDevice = devEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
defaultDevice.AudioEndpointVolume.Mute = true; // or false