-
Notifications
You must be signed in to change notification settings - Fork 0
/
MuteControl.cs
51 lines (40 loc) · 1.18 KB
/
MuteControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using NAudio.CoreAudioApi;
using Serilog;
using System;
using System.Runtime.InteropServices;
namespace GlobalMute
{
internal class MuteControl
{
private readonly MMDevice mmdevice;
public MuteControl()
{
MMDeviceEnumerator enumerator = new MMDeviceEnumerator();
Log.Information("Getting primary audio sink");
try
{
mmdevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications);
}
catch (COMException ex)
{
Log.Fatal(ex, "Error enumerating primary audio sink");
Environment.Exit(1);
}
}
public void ToggleMute()
{
var status = GetMuteStatus();
Log.Information("Mute status: {Status}", status);
SetMuteStatus(!status);
Log.Information("New mute status: {Status}", GetMuteStatus());
}
public bool GetMuteStatus()
{
return mmdevice.AudioEndpointVolume.Mute;
}
public void SetMuteStatus(bool mute)
{
mmdevice.AudioEndpointVolume.Mute = mute;
}
}
}