Add system mute control via setMute action
Introduce a setMute protocol action and an NAudio-backed AudioControlService so the Android client can toggle the Windows render endpoint mute state over WebSocket. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
52
WirelessTextSyncer.Windows/Services/AudioControlService.cs
Normal file
52
WirelessTextSyncer.Windows/Services/AudioControlService.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using NAudio.CoreAudioApi;
|
||||
|
||||
namespace WirelessTextSyncer.Windows.Services;
|
||||
|
||||
public sealed class AudioControlService : IAudioControlService, IDisposable
|
||||
{
|
||||
private readonly MMDeviceEnumerator enumerator = new();
|
||||
private bool disposed;
|
||||
|
||||
public bool IsMuted
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
using var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
|
||||
return device.AudioEndpointVolume.Mute;
|
||||
}
|
||||
catch (COMException exception)
|
||||
{
|
||||
AppLogger.Error("Failed to read audio mute state.", exception);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMute(bool muted)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
|
||||
device.AudioEndpointVolume.Mute = muted;
|
||||
AppLogger.Info($"Audio mute set to {muted}.");
|
||||
}
|
||||
catch (COMException exception)
|
||||
{
|
||||
AppLogger.Error($"Failed to set audio mute to {muted}.", exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
disposed = true;
|
||||
enumerator.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user