/// <summary> /// Switches between the master volume mute states depending on the current state /// </summary> /// <returns>the current mute state, true if the volume was muted, false if unmuted</returns> public static bool ToggleMasterVolumeMute() { Interfaces.IAudioEndpointVolume masterVol = null; try { masterVol = GetMasterVolumeObject(); if (masterVol == null) { return(false); } bool isMuted; masterVol.GetMute(out isMuted); masterVol.SetMute(!isMuted, Guid.Empty); return(!isMuted); } finally { if (masterVol != null) { Marshal.ReleaseComObject(masterVol); } } }
/// <summary> /// Mute or unmute the master volume /// </summary> /// <param name="isMuted">true to mute the master volume, false to unmute</param> public static void SetMasterVolumeMute(bool isMuted) { Interfaces.IAudioEndpointVolume masterVol = null; try { masterVol = GetMasterVolumeObject(); if (masterVol == null) { return; } masterVol.SetMute(isMuted, Guid.Empty); } finally { if (masterVol != null) { Marshal.ReleaseComObject(masterVol); } } }