Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 75886e1

Browse files
MFinkBKjfversluis
andauthored
CameraView: only request microphone permission when CaptureMode is set to Video in UWP (#1963)
CameraView: only request microphone permission when CaptureMode is set to Video Co-authored-by: Gerald Versluis <[email protected]>
1 parent f2b8a2b commit 75886e1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/CommunityToolkit/Xamarin.CommunityToolkit/Views/CameraView/UWP/CameraViewRenderer.uwp.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ protected override async void OnElementPropertyChanged(object? sender, PropertyC
245245
switch (e.PropertyName)
246246
{
247247
case nameof(CameraView.CameraOptions):
248+
case nameof(CameraView.CaptureMode):
248249
await CleanupCameraAsync();
249250
await InitializeCameraAsync();
250251
break;
@@ -333,8 +334,12 @@ async Task InitializeCameraAsync()
333334
return;
334335
}
335336

336-
var audioDevice = await DeviceInformation.FindAllAsync(DeviceClass.AudioCapture);
337-
var selectedAudioDevice = audioDevice.Count == 0 ? null : audioDevice[0].Id;
337+
string? selectedAudioDevice = null;
338+
if (Element.CaptureMode == CameraCaptureMode.Video)
339+
{
340+
var audioDevice = await DeviceInformation.FindAllAsync(DeviceClass.AudioCapture);
341+
selectedAudioDevice = audioDevice.Count == 0 ? null : audioDevice[0].Id;
342+
}
338343

339344
mediaCapture = new MediaCapture();
340345
try
@@ -345,7 +350,7 @@ await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
345350
MediaCategory = MediaCategory.Media,
346351
StreamingCaptureMode = selectedAudioDevice == null ? StreamingCaptureMode.Video : StreamingCaptureMode.AudioAndVideo,
347352
AudioProcessing = Windows.Media.AudioProcessing.Default,
348-
AudioDeviceId = selectedAudioDevice
353+
AudioDeviceId = selectedAudioDevice ?? string.Empty,
349354
});
350355
flash = await Lamp.GetDefaultAsync();
351356

0 commit comments

Comments
 (0)