diff --git a/README.md b/README.md index 1566195a..4940e24e 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,9 @@ camera.postDelayed(new Runnable() { camera.stopRecordingVideo(); } }, 2500); + +// Shorthand: +camera.startRecordingVideo(file, 2500); ``` ### Other camera events diff --git a/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java b/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java index 368f3c7e..db9ce954 100644 --- a/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java +++ b/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java @@ -859,6 +859,34 @@ public class CameraView extends FrameLayout implements LifecycleObserver { } + /** + * Starts recording a video with selected options. Video will be written to the given file, + * so callers should ensure they have appropriate permissions to write to the file. + * Recording will be automatically stopped after durationMillis, unless + * {@link #stopCapturingVideo()} is not called meanwhile. + * + * @param file a file where the video will be saved + * @param durationMillis video max duration + * + * @throws IllegalArgumentException if durationMillis is < 500 milliseconds + */ + public void startCapturingVideo(File file, long durationMillis) { + if (durationMillis < 500) { + throw new IllegalArgumentException("Video duration can't be < 500 milliseconds"); + } + startCapturingVideo(file); + postDelayed(new Runnable() { + @Override + public void run() { + stopCapturingVideo(); + } + }, durationMillis); + } + + + // TODO: pauseCapturingVideo and resumeCapturingVideo. There is mediarecorder.pause(), but API 24... + + /** * Stops capturing video, if there was a video record going on. * This will fire {@link CameraListener#onVideoTaken(File)}. diff --git a/demo/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml index 01d0bd8b..f3bab5c1 100644 --- a/demo/src/main/res/layout/activity_main.xml +++ b/demo/src/main/res/layout/activity_main.xml @@ -23,7 +23,7 @@ android:layout_width="match_parent" android:layout_height="400dp" android:layout_gravity="center_horizontal" - android:adjustViewBounds="true" + android:keepScreenOn="true" app:cameraCropOutput="false" app:cameraFacing="back" app:cameraFlash="off"