Skip to content

Commit

Permalink
video limit param android side
Browse files Browse the repository at this point in the history
  • Loading branch information
parveshneedhoo committed Nov 7, 2024
1 parent 0e55296 commit ec4aa14
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/android/CameraPreviewFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
20 changes: 17 additions & 3 deletions src/android/SimpleCameraPreview.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -181,7 +195,7 @@ public void onError(String errMessage) {
pluginResult.setKeepCallback(true);
videoCallbackContext.sendPluginResult(pluginResult);
}
}, recordWithAudio);
}, recordWithAudio, videoDuration);
}
callbackContext.success();
return true;
Expand Down
3 changes: 2 additions & 1 deletion www/SimpleCameraPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ec4aa14

Please sign in to comment.