From 61c7b68e1ed566f8a625ea02fb19996041e296e6 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Fri, 4 Aug 2017 23:11:43 +0200 Subject: [PATCH] new startCapturingVideo(File, long) for max duration --- README.md | 3 ++ .../com/flurgle/camerakit/CameraView.java | 28 +++++++++++++++++++ demo/src/main/res/layout/activity_main.xml | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) 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"