From d5e1bb16f25416452781b0a1ce293d943ed56271 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Sat, 22 Dec 2018 19:18:20 +0100 Subject: [PATCH] Video files now must not be null --- .../com/otaliastudios/cameraview/IntegrationTest.java | 4 +++- .../java/com/otaliastudios/cameraview/CameraView.java | 10 ++-------- docs/_posts/2018-12-20-v1-migration-guide.md | 3 +++ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/IntegrationTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/IntegrationTest.java index f084fd56..15025fde 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/IntegrationTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/IntegrationTest.java @@ -18,6 +18,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import java.io.File; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -149,7 +150,8 @@ public class IntegrationTest extends BaseTest { private void waitForVideoStart() { controller.mStartVideoTask.listen(); - camera.takeVideo(null); + File file = new File(context().getFilesDir(), "video.mp4"); + camera.takeVideo(file); controller.mStartVideoTask.await(400); } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java index cb41d077..9bcbde04 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java @@ -1284,10 +1284,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { * * @param file a file where the video will be saved */ - public void takeVideo(@Nullable File file) { - if (file == null) { - file = new File(getContext().getFilesDir(), "video.mp4"); - } + public void takeVideo(@NonNull File file) { mCameraController.takeVideo(file); mUiHandler.post(new Runnable() { @Override @@ -1307,11 +1304,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver { * * @param file a file where the video will be saved */ - public void takeVideoSnapshot(@Nullable File file) { + public void takeVideoSnapshot(@NonNull File file) { if (getWidth() == 0 || getHeight() == 0) return; - if (file == null) { - file = new File(getContext().getFilesDir(), "video.mp4"); - } mCameraController.takeVideoSnapshot(file, AspectRatio.of(getWidth(), getHeight())); mUiHandler.post(new Runnable() { @Override diff --git a/docs/_posts/2018-12-20-v1-migration-guide.md b/docs/_posts/2018-12-20-v1-migration-guide.md index 0d6ae21d..9149a803 100644 --- a/docs/_posts/2018-12-20-v1-migration-guide.md +++ b/docs/_posts/2018-12-20-v1-migration-guide.md @@ -117,6 +117,9 @@ Some new APIs were introduced, which are respected by both standard videos and s - `setAudioBitRate()` and `cameraAudioBitRate`: sets the audio bit rate in bit/s - `setVideoBitRate()` and `cameraVideoBitRate`: sets the video bit rate in bit/s +**Important: takeVideo(), like takeVideoSnapshot(), will not accept a null file as input. Use +new File(context.getFilesDir(), "video.mp4") to use the old default.** + ### Camera Preview The type of preview is now configurable with `cameraPreview` XML attribute and `Preview` control class.