Skip to content

Commit 019a895

Browse files
jfversluisCopilot
andcommitted
Enable audio input device selection on Windows
Add AudioDeviceId property to BaseOptions for Windows, allowing consumers to select a specific audio capture device (e.g. Bluetooth headset, USB microphone) by device ID. Changes: - Add BaseOptions.windows.cs with AudioDeviceId string property - Pass AudioDeviceId to MediaCaptureInitializationSettings when specified, before initializing MediaCapture Usage: // Enumerate available capture devices var selector = MediaDevice.GetAudioCaptureSelector(); var devices = await DeviceInformation.FindAllAsync(selector); var btDevice = devices.FirstOrDefault(d => d.Name.Contains("AirPods")); var recorder = audioManager.CreateRecorder(new AudioRecorderOptions { AudioDeviceId = btDevice?.Id }); Companion to #208 (iOS/macCatalyst) and #209 (Android). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1dd3d29 commit 019a895

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/Plugin.Maui.Audio/AudioRecorder/AudioRecorder.windows.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public async Task StartAsync(string filePath, AudioRecorderOptions? options = nu
4949
{
5050
StreamingCaptureMode = StreamingCaptureMode.Audio
5151
};
52+
53+
if (!string.IsNullOrEmpty(audioRecorderOptions.AudioDeviceId))
54+
{
55+
captureSettings.AudioDeviceId = audioRecorderOptions.AudioDeviceId;
56+
}
57+
5258
await InitMediaCapture(captureSettings);
5359
}
5460
catch (Exception ex)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Plugin.Maui.Audio;
2+
3+
partial class BaseOptions
4+
{
5+
/// <summary>
6+
/// Gets or sets the ID of the preferred audio input device.
7+
/// <para>
8+
/// Set this to a device ID obtained from
9+
/// <c>Windows.Devices.Enumeration.DeviceInformation.FindAllAsync</c> using
10+
/// <c>Windows.Media.Devices.MediaDevice.GetAudioCaptureSelector()</c> to record
11+
/// from a specific device (e.g. a Bluetooth headset or USB microphone).
12+
/// When <see langword="null"/>, the system default input device is used.
13+
/// </para>
14+
/// </summary>
15+
public string? AudioDeviceId { get; set; }
16+
}

0 commit comments

Comments
 (0)