Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5aeefebc47 | ||
|
|
ca956f207b | ||
|
|
ad212e7416 |
+19
-10
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user