public DgMic() { MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); _devices = enumerator.EnumerateAudioEndpoints(EDataFlow.ECapture, EDeviceState.DeviceStateActive); _oldState = DgMicStates.Unmuted; _count = _devices.Count; for (int i = 0; i < _count; i++) { _devices[i].AudioEndpointVolume.OnVolumeNotification += AudioEndpointVolume_OnVolumeNotification; } }
public void SetMicStateTo(DgMicStates state) { // Removed this check so the current state remains the responsibility of the caller (i.e. NotifyIconViewModel). // This class now just does whatever it is told to do. //if (_oldState == state) return; for (int i = 0; i < _count; i++) { try { _devices[i].AudioEndpointVolume.Mute = state == DgMicStates.Muted; } catch { //We don't care about it beeing set or not. //Sometimes, it doesn't work. } } }
public void SetMicStateTo(DgMicStates state) { if (_oldState == state) { return; } _oldState = state; for (int i = 0; i < _count; i++) { try { _devices[i].AudioEndpointVolume.Mute = state == DgMicStates.Muted; } catch { //We don't care about it beeing set or not. //Sometimes, it doesn't work. } } }