Compare commits

...
3 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
ckaczor ad212e7416 Log volume notifications
Deploy to Gitea Releases / deploy-to-gitea-releases (push) Successful in 33s
2026-08-18 14:52:56 -04:00
+19 -10
View File
@@ -4,17 +4,17 @@ using Serilog;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows.Threading;
namespace WorkIndicator; namespace WorkIndicator;
internal class AudioDevice : IAudioSessionEventsHandler internal class AudioDevice : IAudioSessionEventsHandler
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly MMDevice _device; private readonly string _friendlyName;
private readonly Dispatcher _dispatcher;
private readonly Dictionary<string, AudioSessionControl> _sessions = new(); private readonly Dictionary<string, AudioSessionControl> _sessions = new();
private bool _muted;
public delegate void AudioSessionsChangedDelegate(); public delegate void AudioSessionsChangedDelegate();
public event AudioSessionsChangedDelegate AudioSessionsChanged; public event AudioSessionsChangedDelegate AudioSessionsChanged;
@@ -23,15 +23,17 @@ internal class AudioDevice : IAudioSessionEventsHandler
{ {
_logger = Log.ForContext<AudioDevice>(); _logger = Log.ForContext<AudioDevice>();
_dispatcher = Dispatcher.CurrentDispatcher; _friendlyName = device.DeviceFriendlyName;
_muted = device.AudioEndpointVolume.Mute;
_device = device; _logger.Information("AudioDevice: {name} {muted}", _friendlyName, _muted);
_device.AudioSessionManager.AudioSessionControl.RegisterEventClient(this); device.AudioEndpointVolume.OnVolumeNotification += AudioEndpointVolume_OnVolumeNotification;
_device.AudioSessionManager.OnSessionCreated += AudioSessionManager_OnSessionCreated; device.AudioSessionManager.AudioSessionControl.RegisterEventClient(this);
device.AudioSessionManager.OnSessionCreated += AudioSessionManager_OnSessionCreated;
_device.AudioSessionManager.RefreshSessions(); device.AudioSessionManager.RefreshSessions();
var sessions = _device.AudioSessionManager.Sessions; var sessions = device.AudioSessionManager.Sessions;
for (var i = 0; i < sessions.Count; i++) for (var i = 0; i < sessions.Count; i++)
{ {
@@ -39,6 +41,13 @@ internal class AudioDevice : IAudioSessionEventsHandler
} }
} }
private void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data)
{
_logger.Information("AudioEndpointVolume_OnVolumeNotification: {name} {muted}", _friendlyName, data.Muted);
_muted = data.Muted;
}
private void AudioSessionManager_OnSessionCreated(object sender, IAudioSessionControl newSession) private void AudioSessionManager_OnSessionCreated(object sender, IAudioSessionControl newSession)
{ {
var session = new AudioSessionControl(newSession); var session = new AudioSessionControl(newSession);
@@ -62,7 +71,7 @@ internal class AudioDevice : IAudioSessionEventsHandler
void IAudioSessionEventsHandler.OnVolumeChanged(float volume, bool isMuted) 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) void IAudioSessionEventsHandler.OnDisplayNameChanged(string displayName)