aboutsummaryrefslogtreecommitdiff
path: root/src/utils/camera.ts
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-07-29 16:34:50 -0400
committerIvan Chen <ivan@tagg.id>2021-07-29 16:34:50 -0400
commit18a1188a2a411e4bb042c922741fea1a5a3aa946 (patch)
tree28dde4f21a9bfb966c574be276b7eaa0f67848ed /src/utils/camera.ts
parent403314805c9192aa7f7adca9605a0d0a52997c9c (diff)
Add max duration constant, Add check for picking video duration, Add logic to cancel recording state
Diffstat (limited to 'src/utils/camera.ts')
-rw-r--r--src/utils/camera.ts16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/utils/camera.ts b/src/utils/camera.ts
index f21ef133..ec2615de 100644
--- a/src/utils/camera.ts
+++ b/src/utils/camera.ts
@@ -10,7 +10,11 @@ import {
} from 'react-native-camera';
import {ProcessingManager} from 'react-native-video-processing';
import ImagePicker, {ImageOrVideo} from 'react-native-image-crop-picker';
-import {ERROR_UPLOAD} from '../constants/strings';
+import {
+ ERROR_UPLOAD,
+ ERROR_UPLOAD_EXCEED_MAX_VIDEO_DURATION,
+} from '../constants/strings';
+import {MAX_VIDEO_RECORDING_DURATION} from '../constants';
/*
* Captures a photo and pauses to show the preview of the picture taken
@@ -39,7 +43,7 @@ export const takeVideo = (
if (cameraRef !== null) {
const options: RecordOptions = {
orientation: 'portrait',
- maxDuration: 60,
+ maxDuration: MAX_VIDEO_RECORDING_DURATION,
quality: '1080p',
};
cameraRef.current?.recordAsync(options).then((vid) => {
@@ -73,6 +77,14 @@ export const navigateToMediaPicker = (
compressVideoPreset: 'Passthrough',
})
.then((media) => {
+ if (
+ 'duration' in media &&
+ media.duration !== null &&
+ media.duration > MAX_VIDEO_RECORDING_DURATION * 1000
+ ) {
+ Alert.alert(ERROR_UPLOAD_EXCEED_MAX_VIDEO_DURATION);
+ return;
+ }
callback(media);
})
.catch((err) => {