Compare commits

...
2 Commits
Author SHA1 Message Date
ckaczor 5aeefebc47 Add logging and track mute state
Deploy to Gitea Releases / deploy-to-gitea-releases (push) Successful in 33s
2026-08-18 15:18:25 -04:00
ckaczor ca956f207b Adjust mute detection/logging
Deploy to Gitea Releases / deploy-to-gitea-releases (push) Successful in 33s
2026-08-18 14:59:20 -04:00
+15 -12
View File
@@ -4,17 +4,17 @@ using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Threading;
namespace WorkIndicator;
internal class AudioDevice : IAudioSessionEventsHandler
{
private readonly ILogger _logger;
private readonly MMDevice _device;
private readonly Dispatcher _dispatcher;
private readonly string _friendlyName;
private readonly Dictionary<string, AudioSessionControl> _sessions = new();
private bool _muted;
public delegate void AudioSessionsChangedDelegate();
public event AudioSessionsChangedDelegate AudioSessionsChanged;
@@ -23,16 +23,17 @@ internal class AudioDevice : IAudioSessionEventsHandler
{
_logger = Log.ForContext<AudioDevice>();
_dispatcher = Dispatcher.CurrentDispatcher;
_friendlyName = device.DeviceFriendlyName;
_muted = device.AudioEndpointVolume.Mute;
_device = device;
_logger.Information("AudioDevice: {name} {muted}", _friendlyName, _muted);
_device.AudioEndpointVolume.OnVolumeNotification += AudioEndpointVolume_OnVolumeNotification;
_device.AudioSessionManager.AudioSessionControl.RegisterEventClient(this);
_device.AudioSessionManager.OnSessionCreated += AudioSessionManager_OnSessionCreated;
device.AudioEndpointVolume.OnVolumeNotification += AudioEndpointVolume_OnVolumeNotification;
device.AudioSessionManager.AudioSessionControl.RegisterEventClient(this);
device.AudioSessionManager.OnSessionCreated += AudioSessionManager_OnSessionCreated;
_device.AudioSessionManager.RefreshSessions();
var sessions = _device.AudioSessionManager.Sessions;
device.AudioSessionManager.RefreshSessions();
var sessions = device.AudioSessionManager.Sessions;
for (var i = 0; i < sessions.Count; i++)
{
@@ -42,7 +43,9 @@ internal class AudioDevice : IAudioSessionEventsHandler
private void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data)
{
_logger.Information("AudioEndpointVolume_OnVolumeNotification: {guid} {muted}", data.Guid, data.Muted);
_logger.Information("AudioEndpointVolume_OnVolumeNotification: {name} {muted}", _friendlyName, data.Muted);
_muted = data.Muted;
}
private void AudioSessionManager_OnSessionCreated(object sender, IAudioSessionControl newSession)
@@ -68,7 +71,7 @@ internal class AudioDevice : IAudioSessionEventsHandler
void IAudioSessionEventsHandler.OnVolumeChanged(float volume, bool isMuted)
{
_dispatcher.Invoke(() => { _logger.Information("{name}: {volume} {isMuted} {mute}", _device.DeviceFriendlyName, volume, isMuted, _device.AudioEndpointVolume.Mute); });
_logger.Information("OnVolumeChanged: {name} {volume} {isMuted}", _friendlyName, volume, isMuted);
}
void IAudioSessionEventsHandler.OnDisplayNameChanged(string displayName)