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

Commit

Permalink
CameraView: only request microphone permission when CaptureMode is se…
Browse files Browse the repository at this point in the history
…t to Video in UWP (#1963)

CameraView: only request microphone permission when CaptureMode is set to Video

Co-authored-by: Gerald Versluis <[email protected]>
  • Loading branch information
MFinkBK and jfversluis authored May 1, 2023
1 parent f2b8a2b commit 75886e1
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ protected override async void OnElementPropertyChanged(object? sender, PropertyC
switch (e.PropertyName)
{
case nameof(CameraView.CameraOptions):
case nameof(CameraView.CaptureMode):
await CleanupCameraAsync();
await InitializeCameraAsync();
break;
Expand Down Expand Up @@ -333,8 +334,12 @@ async Task InitializeCameraAsync()
return;
}

var audioDevice = await DeviceInformation.FindAllAsync(DeviceClass.AudioCapture);
var selectedAudioDevice = audioDevice.Count == 0 ? null : audioDevice[0].Id;
string? selectedAudioDevice = null;
if (Element.CaptureMode == CameraCaptureMode.Video)
{
var audioDevice = await DeviceInformation.FindAllAsync(DeviceClass.AudioCapture);
selectedAudioDevice = audioDevice.Count == 0 ? null : audioDevice[0].Id;
}

mediaCapture = new MediaCapture();
try
Expand All @@ -345,7 +350,7 @@ await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
MediaCategory = MediaCategory.Media,
StreamingCaptureMode = selectedAudioDevice == null ? StreamingCaptureMode.Video : StreamingCaptureMode.AudioAndVideo,
AudioProcessing = Windows.Media.AudioProcessing.Default,
AudioDeviceId = selectedAudioDevice
AudioDeviceId = selectedAudioDevice ?? string.Empty,
});
flash = await Lamp.GetDefaultAsync();

Expand Down

0 comments on commit 75886e1

Please sign in to comment.