-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Mute): Add service to mute default microphone
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
SoundSwitch/Framework/Audio/Microphone/MicrophoneMuteToggler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
} | ||
} |