Skip to content

Commit

Permalink
refactor(AudioSwitcher): Get wanted device
Browse files Browse the repository at this point in the history
  • Loading branch information
Belphemur committed Sep 4, 2021
1 parent 96e080a commit 8b1981d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions SoundSwitch.Audio.Manager/AudioSwitcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ public string GetUsedDevice(EDataFlow flow, ERole role, uint processId)
/// <returns>Null if no default device is defined</returns>
public MMDevice? GetDefaultMmDevice(EDataFlow flow, ERole role) => ComThread.Invoke(() => EnumeratorClient.GetDefaultEndpoint(flow, role));

/// <summary>
/// Get a device with the given id, returns null if not present
/// </summary>
/// <param name="deviceId"></param>
/// <returns></returns>
public MMDevice? GetDevice(string deviceId) => ComThread.Invoke(() => EnumeratorClient.GetDevice(deviceId));

/// <summary>
/// Reset Windows configuration for the process that had their audio device changed
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion SoundSwitch.Audio.Manager/Interop/Client/EnumeratorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public bool IsDefault(string deviceId, EDataFlow flow, ERole role)
{
try
{
var defaultDevice = _enumerator.GetDefaultAudioEndpoint((DataFlow) flow, (Role) role);
var defaultDevice = _enumerator.GetDefaultAudioEndpoint((DataFlow)flow, (Role)role);
return defaultDevice;
}
catch (Exception)
Expand All @@ -58,6 +58,21 @@ public bool IsDefault(string deviceId, EDataFlow flow, ERole role)
}
}

/// <summary>
/// Get device with the given id
/// </summary>
public MMDevice? GetDevice(string deviceId)
{
try
{
return _enumerator.GetDevice(deviceId);
}
catch
{
return null;
}
}

[ComImport, Guid(ComGuid.AUDIO_IMMDEVICE_ENUMERATOR_OBJECT_IID)]
private class _MMDeviceEnumerator
{
Expand Down
2 changes: 1 addition & 1 deletion SoundSwitch.Audio.Manager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.1.0.*")]
[assembly: AssemblyVersion("3.2.0.*")]

0 comments on commit 8b1981d

Please sign in to comment.