Skip to content

Commit

Permalink
fix(Mute): Use the right context to interact with the MMDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
Belphemur committed Apr 2, 2021
1 parent 777d5a8 commit 4ef87a4
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions SoundSwitch/Framework/Audio/Microphone/MicrophoneMuteToggler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,29 @@ public MicrophoneMuteToggler(AudioSwitcher switcher)
/// <summary>
/// Toggle mute state for the default microphone
/// </summary>
/// <param name="deviceId"></param>
public void ToggleDefaultMute()
public bool ToggleDefaultMute()
{
var microphone = _switcher.GetDefaultMmDevice(EDataFlow.eCapture, ERole.eCommunications);
if (microphone == null)
{
Log.Information("Couldn't find a default microphone to toggle mute");
return;
return false;
}

try
return _switcher.InteractWithMmDevice(microphone, device =>
{
microphone.AudioEndpointVolume.Mute = !microphone.AudioEndpointVolume.Mute;
}
catch (Exception e)
{
Log.Error("Couldn't toggle mute on {device}:\n{exception}", microphone.FriendlyName, e);
}

try
{
device.AudioEndpointVolume.Mute = !microphone.AudioEndpointVolume.Mute;
return true;
}
catch (Exception e)
{
Log.Error("Couldn't toggle mute on {device}:\n{exception}", microphone.FriendlyName, e);
}

return false;
});
}
}
}

0 comments on commit 4ef87a4

Please sign in to comment.