Skip to content

Commit

Permalink
feat(Mute): Return the state of mute after action
Browse files Browse the repository at this point in the history
  • Loading branch information
Belphemur committed Apr 2, 2021
1 parent 4ef87a4 commit 6d63226
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions SoundSwitch/Framework/Audio/Microphone/MicrophoneMuteToggler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,31 @@ public MicrophoneMuteToggler(AudioSwitcher switcher)

/// <summary>
/// Toggle mute state for the default microphone
/// <returns>The current mute state, null if couldn't interact with the microphone</returns>
/// </summary>
public bool 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 false;
return null;
}

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

return false;
return null;
});
}
}
Expand Down

0 comments on commit 6d63226

Please sign in to comment.