From ec4aa14788afe1dec40dfa0d2ae0fc887d9e498c Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Thu, 7 Nov 2024 11:49:28 +0400 Subject: [PATCH 1/6] video limit param android side --- src/android/CameraPreviewFragment.java | 4 ++-- src/android/SimpleCameraPreview.java | 20 +++++++++++++++++--- www/SimpleCameraPreview.js | 3 ++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/android/CameraPreviewFragment.java b/src/android/CameraPreviewFragment.java index f799c8a..0ed6e20 100644 --- a/src/android/CameraPreviewFragment.java +++ b/src/android/CameraPreviewFragment.java @@ -285,7 +285,7 @@ public void hasFlash(HasFlashCallback hasFlashCallback) { hasFlashCallback.onResult(camera.getCameraInfo().hasFlashUnit()); } - public void startVideoCapture(VideoCallback videoCallback, boolean recordWithAudio) { + public void startVideoCapture(VideoCallback videoCallback, boolean recordWithAudio, int videoDuration) { if (recording != null) { recording.stop(); recording = null; @@ -308,7 +308,7 @@ public void startVideoCapture(VideoCallback videoCallback, boolean recordWithAud public void run() { stopVideoCapture(); } - }, 30000); + }, videoDuration); PendingRecording pendingRecording = videoCapture.getOutput() .prepareRecording(this.getContext().getApplicationContext(), outputOptions); diff --git a/src/android/SimpleCameraPreview.java b/src/android/SimpleCameraPreview.java index f259d7f..a6ec81a 100644 --- a/src/android/SimpleCameraPreview.java +++ b/src/android/SimpleCameraPreview.java @@ -79,7 +79,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo return initVideoCallback(callbackContext); case "startVideoCapture": - return startVideoCapture(args.getBoolean(0), callbackContext); + return startVideoCapture((JSONObject) args.get(0), callbackContext); case "stopVideoCapture": return stopVideoCapture(callbackContext); @@ -120,12 +120,26 @@ private boolean initVideoCallback(CallbackContext callbackContext) { return true; } - private boolean startVideoCapture(boolean recordWithAudio, CallbackContext callbackContext) { + private boolean startVideoCapture(JSONObject options, CallbackContext callbackContext) { if (fragment == null) { callbackContext.error("Camera is closed"); return true; } + boolean recordWithAudio = false; + try { + recordWithAudio = options.getBoolean("recordWithAudio"); + } catch (JSONException e) { + throw new RuntimeException(e); + } + + int videoDuration = 3000; + try { + videoDuration = options.getInt("videoDurationMs"); + } catch (JSONException e) { + throw new RuntimeException(e); + } + if (recordWithAudio && !PermissionHelper.hasPermission(this, Manifest.permission.RECORD_AUDIO)) { String[] permissions = {Manifest.permission.RECORD_AUDIO}; PermissionHelper.requestPermissions(this, VIDEO_REQUEST_CODE_PERMISSIONS, permissions); @@ -181,7 +195,7 @@ public void onError(String errMessage) { pluginResult.setKeepCallback(true); videoCallbackContext.sendPluginResult(pluginResult); } - }, recordWithAudio); + }, recordWithAudio, videoDuration); } callbackContext.success(); return true; diff --git a/www/SimpleCameraPreview.js b/www/SimpleCameraPreview.js index 1bdfa29..03136cc 100755 --- a/www/SimpleCameraPreview.js +++ b/www/SimpleCameraPreview.js @@ -20,7 +20,8 @@ SimpleCameraPreview.startVideoCapture = function (options, onSuccess, onError) { options = options || {}; options.recordWithAudio = options.recordWithAudio != null ? options.recordWithAudio : true; - exec(onSuccess, onError, PLUGIN_NAME, "startVideoCapture", [options.recordWithAudio]); + options.videoDurationMs = options.videoDurationMs != null ? options.videoDurationMs : 3000; + exec(onSuccess, onError, PLUGIN_NAME, "startVideoCapture", [options]); }; SimpleCameraPreview.stopVideoCapture = function (onSuccess, onError) { From 353f2c80f4d21dbed9f204aea295494abacc3350 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Thu, 7 Nov 2024 12:39:13 +0400 Subject: [PATCH 2/6] video limit ios side --- src/ios/CameraSessionManager.h | 2 +- src/ios/CameraSessionManager.m | 6 ++++-- src/ios/SimpleCameraPreview.m | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ios/CameraSessionManager.h b/src/ios/CameraSessionManager.h index 4d0a07f..96a79dc 100644 --- a/src/ios/CameraSessionManager.h +++ b/src/ios/CameraSessionManager.h @@ -12,7 +12,7 @@ - (BOOL) deviceHasUltraWideCamera; - (void) deallocSession; - (void) updateOrientation:(AVCaptureVideoOrientation)orientation; -- (void) startRecording:(NSURL *)fileURL recordingDelegate:(id)recordingDelegate; +- (void) startRecording:(NSURL *)fileURL recordingDelegate:(id)recordingDelegate videoDurationMs:(NSInteger)videoDuration; - (void) stopRecording; - (AVCaptureVideoOrientation) getCurrentOrientation:(UIInterfaceOrientation)toInterfaceOrientation; + (AVCaptureSessionPreset) calculateResolution:(NSInteger)targetSize; diff --git a/src/ios/CameraSessionManager.m b/src/ios/CameraSessionManager.m index 3f0c81e..4500985 100644 --- a/src/ios/CameraSessionManager.m +++ b/src/ios/CameraSessionManager.m @@ -239,14 +239,16 @@ - (void)switchCameraTo:(NSString*)cameraMode completion:(void (^)(BOOL success)) }); } -- (void)startRecording:(NSURL *)fileURL recordingDelegate:(id)recordingDelegate { +- (void)startRecording:(NSURL *)fileURL recordingDelegate:(id)recordingDelegate videoDurationMs:(NSInteger)videoDurationMs { if (!self.movieFileOutput.isRecording) { AVCaptureConnection *connection = [self.movieFileOutput connectionWithMediaType:AVMediaTypeVideo]; if ([connection isVideoOrientationSupported]) { connection.videoOrientation = [self getCurrentOrientation]; } [self.movieFileOutput startRecordingToOutputFileURL:fileURL recordingDelegate:recordingDelegate]; - _videoTimer = [NSTimer scheduledTimerWithTimeInterval:30.0 + + NSInteger videoDurationInSec = videoDurationMs / 1000; + _videoTimer = [NSTimer scheduledTimerWithTimeInterval:videoDurationInSec target:self selector:@selector(stopRecording) userInfo:nil diff --git a/src/ios/SimpleCameraPreview.m b/src/ios/SimpleCameraPreview.m index 5fa2b28..af7dbf7 100644 --- a/src/ios/SimpleCameraPreview.m +++ b/src/ios/SimpleCameraPreview.m @@ -368,13 +368,16 @@ - (void) initVideoCallback:(CDVInvokedUrlCommand*)command { } - (void)startVideoCapture:(CDVInvokedUrlCommand*)command { + NSDictionary* config = command.arguments[0]; + NSInteger videoDuration = ((NSNumber*)config[@"videoDurationMs"]).intValue; + if (self.sessionManager != nil && !self.sessionManager.movieFileOutput.isRecording) { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); NSString *libraryDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"NoCloud"]; NSString* uniqueFileName = [NSString stringWithFormat:@"%@.mp4",[[NSUUID UUID] UUIDString]]; NSString *dataPath = [libraryDirectory stringByAppendingPathComponent:uniqueFileName]; NSURL *fileURL = [NSURL fileURLWithPath:dataPath]; - [self.sessionManager startRecording:fileURL recordingDelegate:self]; + [self.sessionManager startRecording:fileURL recordingDelegate:self videoDurationMs:videoDuration]; } else { CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Session not initialized or already recording"]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; From f5f0bc5d28c50e97c01d487393e9b85023deb06b Mon Sep 17 00:00:00 2001 From: YushraJewon Date: Thu, 7 Nov 2024 17:37:35 +0400 Subject: [PATCH 3/6] remove default 3000 in startVideoCapture --- src/android/SimpleCameraPreview.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/SimpleCameraPreview.java b/src/android/SimpleCameraPreview.java index a6ec81a..e651ff4 100644 --- a/src/android/SimpleCameraPreview.java +++ b/src/android/SimpleCameraPreview.java @@ -133,7 +133,7 @@ private boolean startVideoCapture(JSONObject options, CallbackContext callbackCo throw new RuntimeException(e); } - int videoDuration = 3000; + int videoDuration; try { videoDuration = options.getInt("videoDurationMs"); } catch (JSONException e) { From ce6b25b6f9c8e3b8b533072e8b9a6cc696be3b3a Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Fri, 8 Nov 2024 10:07:06 +0400 Subject: [PATCH 4/6] remove default value for "recordWithAudio" params --- src/android/SimpleCameraPreview.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/SimpleCameraPreview.java b/src/android/SimpleCameraPreview.java index e651ff4..f85998b 100644 --- a/src/android/SimpleCameraPreview.java +++ b/src/android/SimpleCameraPreview.java @@ -126,7 +126,7 @@ private boolean startVideoCapture(JSONObject options, CallbackContext callbackCo return true; } - boolean recordWithAudio = false; + boolean recordWithAudio; try { recordWithAudio = options.getBoolean("recordWithAudio"); } catch (JSONException e) { From f90404a3f0144e03610688ad693751eec665419f Mon Sep 17 00:00:00 2001 From: dinitri Date: Thu, 28 Nov 2024 20:27:06 +0400 Subject: [PATCH 5/6] catch --- src/android/SimpleCameraPreview.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/android/SimpleCameraPreview.java b/src/android/SimpleCameraPreview.java index f85998b..33129cb 100644 --- a/src/android/SimpleCameraPreview.java +++ b/src/android/SimpleCameraPreview.java @@ -130,14 +130,16 @@ private boolean startVideoCapture(JSONObject options, CallbackContext callbackCo try { recordWithAudio = options.getBoolean("recordWithAudio"); } catch (JSONException e) { - throw new RuntimeException(e); + e.printStackTrace(); + recordWithAudio = false; } int videoDuration; try { videoDuration = options.getInt("videoDurationMs"); } catch (JSONException e) { - throw new RuntimeException(e); + e.printStackTrace(); + videoDuration = 3000; } if (recordWithAudio && !PermissionHelper.hasPermission(this, Manifest.permission.RECORD_AUDIO)) { From c5eac4fad42c11cce1ec978c4f703a8f4796670d Mon Sep 17 00:00:00 2001 From: dinitri Date: Thu, 28 Nov 2024 20:38:55 +0400 Subject: [PATCH 6/6] bump version --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- plugin.xml | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23fc88e..9578b5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [2.0.32](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/compare/2.0.31...2.0.32) (2024-11-28) +* **Android:** Use videoDuration parameter to configure duration of a video +* **iOS:** Use videoDuration parameter to configure duration of a video + ## [2.0.31](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/compare/2.0.30...2.0.31) (2024-11-04) * **iOS:** Automatic stop video after 30s diff --git a/package-lock.json b/package-lock.json index db58461..d915991 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@spoonconsulting/cordova-plugin-simple-camera-preview", - "version": "2.0.31", + "version": "2.0.32", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@spoonconsulting/cordova-plugin-simple-camera-preview", - "version": "2.0.31", + "version": "2.0.32", "license": "Apache 2.0", "devDependencies": {} } diff --git a/package.json b/package.json index f4511fa..bf69460 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spoonconsulting/cordova-plugin-simple-camera-preview", - "version": "2.0.31", + "version": "2.0.32", "description": "Cordova plugin that allows camera interaction from HTML code for showing camera preview below or on top of the HTML.", "keywords": [ "cordova", diff --git a/plugin.xml b/plugin.xml index fe5f0ad..a78825f 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,6 +1,6 @@ - + cordova-plugin-simple-camera-preview Cordova plugin that allows camera interaction from HTML code. Show camera preview popup on top of the HTML.