Public Access
55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
namespace MeetingAssistant.Recording;
|
|
|
|
public sealed class MicrophoneDeviceSelection
|
|
{
|
|
private readonly object sync = new();
|
|
private string? selectedDeviceId;
|
|
|
|
public string? SelectedDeviceId
|
|
{
|
|
get
|
|
{
|
|
lock (sync)
|
|
{
|
|
return selectedDeviceId;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Select(string deviceId)
|
|
{
|
|
lock (sync)
|
|
{
|
|
selectedDeviceId = string.IsNullOrWhiteSpace(deviceId)
|
|
? null
|
|
: deviceId.Trim();
|
|
}
|
|
}
|
|
|
|
public MicrophoneDevice? Resolve(
|
|
string? configuredDeviceId,
|
|
MicrophoneDevice? defaultDevice,
|
|
IReadOnlyList<MicrophoneDevice> availableDevices)
|
|
{
|
|
var selected = SelectedDeviceId;
|
|
return FindById(availableDevices, selected) ??
|
|
FindById(availableDevices, configuredDeviceId) ??
|
|
defaultDevice;
|
|
}
|
|
|
|
private static MicrophoneDevice? FindById(
|
|
IReadOnlyList<MicrophoneDevice> devices,
|
|
string? id)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(id))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return devices.FirstOrDefault(device => string.Equals(
|
|
device.Id,
|
|
id.Trim(),
|
|
StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
}
|