Skip to content

Commit cbe121c

Browse files
committed
feat(Mute): Add service to mute default microphone
1 parent 36bf86a commit cbe121c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

.idea/.idea.SoundSwitch/.idea/contentModel.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using Serilog;
3+
using SoundSwitch.Audio.Manager;
4+
using SoundSwitch.Audio.Manager.Interop.Enum;
5+
6+
namespace SoundSwitch.Framework.Audio.Microphone
7+
{
8+
public class MicrophoneMuteToggler
9+
{
10+
private readonly AudioSwitcher _switcher;
11+
12+
public MicrophoneMuteToggler(AudioSwitcher switcher)
13+
{
14+
_switcher = switcher;
15+
}
16+
17+
/// <summary>
18+
/// Toggle mute state for the default microphone
19+
/// </summary>
20+
/// <param name="deviceId"></param>
21+
public void ToggleDefaultMute()
22+
{
23+
var microphone = _switcher.GetDefaultMmDevice(EDataFlow.eCapture, ERole.eCommunications);
24+
if (microphone == null)
25+
{
26+
Log.Information("Couldn't find a default microphone to toggle mute");
27+
return;
28+
}
29+
30+
try
31+
{
32+
microphone.AudioEndpointVolume.Mute = !microphone.AudioEndpointVolume.Mute;
33+
}
34+
catch (Exception e)
35+
{
36+
Log.Error("Couldn't toggle mute on {device}:\n{exception}", microphone.FriendlyName, e);
37+
}
38+
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)