-
Notifications
You must be signed in to change notification settings - Fork 492
fix: allow camera usage when microphone permission is denied on Windows #3140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||
| using CommunityToolkit.Maui.Core; | ||||||
| using Windows.Devices.Enumeration; | ||||||
| using Windows.Media; | ||||||
| using Windows.Media.Capture; | ||||||
|
|
||||||
| namespace CommunityToolkit.Maui.Extensions; | ||||||
|
|
@@ -13,20 +14,44 @@ public static async Task UpdateAvailability(this ICameraView cameraView, Cancell | |||||
| cameraView.IsAvailable = videoCaptureDevices.Count > 0; | ||||||
| } | ||||||
|
|
||||||
| public static Task InitializeCameraForCameraView(this MediaCapture mediaCapture, string deviceId, CancellationToken token) | ||||||
| public static async Task InitializeCameraForCameraView(this MediaCapture mediaCapture, string deviceId, CancellationToken token) | ||||||
| { | ||||||
| try | ||||||
| { | ||||||
| return mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings | ||||||
| var settings = new MediaCaptureInitializationSettings | ||||||
| { | ||||||
| VideoDeviceId = deviceId, | ||||||
| PhotoCaptureSource = PhotoCaptureSource.Auto | ||||||
| }).AsTask(token); | ||||||
| }; | ||||||
|
|
||||||
| PermissionStatus microphonePermissionStatus = PermissionStatus.Unknown; | ||||||
| var isMicrophoneCapable = Permissions.IsCapabilityDeclared("microphone"); | ||||||
|
|
||||||
| if (isMicrophoneCapable) | ||||||
| { | ||||||
| microphonePermissionStatus = await Permissions.CheckStatusAsync<Permissions.Microphone>(); | ||||||
| } | ||||||
|
|
||||||
| if (!isMicrophoneCapable || microphonePermissionStatus != PermissionStatus.Granted) | ||||||
| { | ||||||
| settings.StreamingCaptureMode = StreamingCaptureMode.Video; | ||||||
| settings.MediaCategory = MediaCategory.Media; | ||||||
| settings.AudioProcessing = AudioProcessing.Default; | ||||||
| } | ||||||
|
|
||||||
| var cameraPermissionStatus = await Permissions.CheckStatusAsync<Permissions.Camera>(); | ||||||
| if (cameraPermissionStatus == PermissionStatus.Granted) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We removed all permission checks from the library. It is now up to developers to request permission they need and when they need, with the way to use their own UI for user permissions.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the clarification.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @VladislavAntonyuk How can we proceed? Can you check my comment |
||||||
| { | ||||||
| await mediaCapture.InitializeAsync(settings).AsTask(token); | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| throw new CameraException("Camera permission is not granted."); | ||||||
|
||||||
| throw new CameraException("Camera permission is not granted."); | |
| throw new CameraException("Camera permission is not granted. To enable camera access, open Windows Settings > Privacy & security > Camera and allow camera access for this app."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PermissionsandPermissionStatusare used in this file, but there is nousing Microsoft.Maui.ApplicationModel;(or fully-qualified references). Unless there’s a project-wide global using (none found in this project), this will not compile on Windows. Add the appropriate using or fully qualify the types.