1
1
#nullable enable
2
+ using System ;
2
3
using System . Diagnostics ;
3
4
using System . Linq ;
4
5
using NAudio . CoreAudioApi ;
@@ -12,9 +13,9 @@ namespace SoundSwitch.Audio.Manager
12
13
{
13
14
public class AudioSwitcher
14
15
{
15
- private static AudioSwitcher _instance ;
16
- private PolicyClient _policyClient ;
17
- private EnumeratorClient _enumerator ;
16
+ private static AudioSwitcher _instance ;
17
+ private PolicyClient _policyClient ;
18
+ private EnumeratorClient _enumerator ;
18
19
19
20
private ExtendedPolicyClient _extendedPolicyClient ;
20
21
@@ -177,12 +178,20 @@ public string GetUsedDevice(EDataFlow flow, ERole role, uint processId)
177
178
/// <param name="flow"></param>
178
179
/// <param name="role"></param>
179
180
/// <returns>Null if no default device is defined</returns>
180
- public DeviceFullInfo ? GetDefaultAudioEndpoint ( EDataFlow flow , ERole role )
181
+ public DeviceFullInfo ? GetDefaultAudioEndpoint ( EDataFlow flow , ERole role ) => ComThread . Invoke ( ( ) =>
181
182
{
182
- var defaultEndpoint = GetDefaultMmDevice ( flow , role ) ;
183
+ var defaultEndpoint = EnumeratorClient . GetDefaultEndpoint ( flow , role ) ;
183
184
return defaultEndpoint == null ? null : new DeviceFullInfo ( defaultEndpoint ) ;
184
- }
185
-
185
+ } ) ;
186
+
187
+ /// <summary>
188
+ /// Used to interact directly with a <see cref="MMDevice"/>
189
+ /// </summary>
190
+ /// <param name="device"></param>
191
+ /// <param name="interaction"></param>
192
+ /// <typeparam name="T"></typeparam>
193
+ public void InteractWithMmDevice < T > ( MMDevice device , Func < MMDevice , T > interaction ) => ComThread . Invoke ( ( ) => interaction ( device ) ) ;
194
+
186
195
/// <summary>
187
196
/// Get the current default endpoint
188
197
/// </summary>
0 commit comments