Skip to content

Commit

Permalink
feat(Mute): Add service to mute default microphone
Browse files Browse the repository at this point in the history
  • Loading branch information
Belphemur committed Apr 2, 2021
1 parent 36bf86a commit cbe121c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .idea/.idea.SoundSwitch/.idea/contentModel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions SoundSwitch/Framework/Audio/Microphone/MicrophoneMuteToggler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using Serilog;
using SoundSwitch.Audio.Manager;
using SoundSwitch.Audio.Manager.Interop.Enum;

namespace SoundSwitch.Framework.Audio.Microphone
{
public class MicrophoneMuteToggler
{
private readonly AudioSwitcher _switcher;

public MicrophoneMuteToggler(AudioSwitcher switcher)
{
_switcher = switcher;
}

/// <summary>
/// Toggle mute state for the default microphone
/// </summary>
/// <param name="deviceId"></param>
public void ToggleDefaultMute()
{
var microphone = _switcher.GetDefaultMmDevice(EDataFlow.eCapture, ERole.eCommunications);
if (microphone == null)
{
Log.Information("Couldn't find a default microphone to toggle mute");
return;
}

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

}
}
}

0 comments on commit cbe121c

Please sign in to comment.