Skip to content
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

feat(ios): support capture 'quality' param for videos #214

Merged
merged 6 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ capturing a video clip, the `CaptureErrorCB` callback executes with a

- __duration__: The maximum duration of a video clip, in seconds.

- __quality__: To allow capturing video at different qualities. A value of `1` ( the default ) means high quality and value of `0` means low quality, suitable for MMS messages.

### Example

// limit capture operation to 3 video clips
Expand All @@ -363,12 +365,15 @@ capturing a video clip, the `CaptureErrorCB` callback executes with a

- The __limit__ property is ignored. Only one video is recorded per invocation.

- The __quality__ property can have a value of `0.5` for medium quality.

- See [here](https://developer.apple.com/documentation/uikit/uiimagepickercontroller/1619154-videoquality?language=objc) for more details about the __quality__ property on iOS.

### Android Quirks

- Android supports an additional __quality__ property, to allow capturing video at different qualities. A value of `1` ( the default ) means high quality and value of `0` means low quality, suitable for MMS messages.
See [here](http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_VIDEO_QUALITY) for more details.
- See [here](http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_VIDEO_QUALITY) for more details about the __quality__ property on Android.

### Example ( Android w/ quality )
### Example ( w/ quality )

// limit capture operation to 1 video clip of low quality
var options = { limit: 1, quality: 0 };
Expand Down
16 changes: 14 additions & 2 deletions src/ios/CDVCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command
options = [NSDictionary dictionary];
}

// options could contain limit, duration and mode
// options could contain limit, duration, quality and mode
// taking more than one video (limit) is only supported if provide own controls via cameraOverlayView property
NSNumber* duration = [options objectForKey:@"duration"];
NSNumber* quality = [options objectForKey:@"quality"];
NSString* mediaType = nil;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
Expand Down Expand Up @@ -266,7 +267,18 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command
// iOS 4.0
if ([pickerController respondsToSelector:@selector(cameraCaptureMode)]) {
pickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
// pickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
switch ((int) (quality ? [quality doubleValue] * 10 : -1)) {
case 0:
pickerController.videoQuality = UIImagePickerControllerQualityTypeLow;
break;
case 5:
pickerController.videoQuality = UIImagePickerControllerQualityTypeMedium;
break;
case 10:
default:
pickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
break;
}
// pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
// pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
}
Expand Down