-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[camera] Request access permission for audio #5766
Changes from 3 commits
e8e213e
141025c
67f9435
cb3ecc6
a169b34
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 | ||||
---|---|---|---|---|---|---|
|
@@ -5,35 +5,81 @@ | |||||
@import AVFoundation; | ||||||
#import "CameraPermissionUtils.h" | ||||||
|
||||||
void FLTRequestCameraPermissionWithCompletionHandler( | ||||||
FLTCameraPermissionRequestCompletionHandler handler) { | ||||||
switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]) { | ||||||
void RequestPermission(BOOL forAudio, FLTCameraPermissionRequestCompletionHandler handler) { | ||||||
|
void RequestPermission(BOOL forAudio, FLTCameraPermissionRequestCompletionHandler handler) { | |
void FLTRequestPermission(BOOL forAudio, FLTCameraPermissionRequestCompletionHandler handler) { |
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.
I know authorizationStatusForMediaType:mediaType
was already used before, but should this be +requestAccessForMediaType:completionHandler:
instead to actually request it?
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.
Oh we should always check the status first, and only request the permission if it's in .notDetermined
status.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,7 +132,7 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call | |
[result sendNotImplemented]; | ||
} | ||
} else if ([@"create" isEqualToString:call.method]) { | ||
FLTRequestCameraPermissionWithCompletionHandler(^(FlutterError *error) { | ||
FLTRequestCameraPermission(^(FlutterError *error) { | ||
|
||
// Create FLTCam only if granted camera access. | ||
if (error) { | ||
[result sendFlutterError:error]; | ||
|
@@ -194,8 +194,19 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call | |
[_camera close]; | ||
[result sendSuccess]; | ||
} else if ([@"prepareForVideoRecording" isEqualToString:call.method]) { | ||
[_camera setUpCaptureSessionForAudio]; | ||
[result sendSuccess]; | ||
// Setup audio capture session only if granted audio access. | ||
FLTRequestAudioPermission(^(FlutterError *error) { | ||
if (error) { | ||
[result sendFlutterError:error]; | ||
} else { | ||
// Permission completion handler may be called on arbitrary queue. | ||
// Dispatch to `captureSessionQueue` to setup audio capture session. | ||
dispatch_async(self.captureSessionQueue, ^{ | ||
[self.camera setUpCaptureSessionForAudio]; | ||
[result sendSuccess]; | ||
}); | ||
} | ||
}); | ||
} else if ([@"startVideoRecording" isEqualToString:call.method]) { | ||
[_camera startVideoRecordingWithResult:result]; | ||
} else if ([@"stopVideoRecording" isEqualToString:call.method]) { | ||
|
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.
So per your design doc edits this will also be implemented for Android?
plugins/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/CameraPermissions.java
Line 29 in 7686be7
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.
Yep, android also handles camera and audio permissions separately.