robertlevonyan / camerax-demo Goto Github PK
View Code? Open in Web Editor NEWA sample camera app with CameraX API from Android Jetpack
License: MIT License
A sample camera app with CameraX API from Android Jetpack
License: MIT License
import com.robertlevonyan.demo.camerax.databinding.FragmentCameraBinding
We are getting the below error on the log console if we are capturing the photo. Please help me if anyone have already fixed it.
java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List android.hardware.camera2.params.OutputConfiguration.getSurfaces()' on a null object reference
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onCaptureErrorLocked(CameraDeviceImpl.java:2130)
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onDeviceError(CameraDeviceImpl.java:1800)
at android.hardware.camera2.legacy.CameraDeviceUserShim$CameraCallbackThread$CallbackHandler.handleMessage(CameraDeviceUserShim.java:309)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:206)
at android.os.HandlerThread.run(HandlerThread.java:65)
************ DEVICE INFORMATION ***********
Brand: lenovo
Device: manning
Model: Lenovo K8 Note
Id: OMB27.43-70
Product: manning_retail
************ FIRMWARE ************
SDK: 26
Release: 8.0.0
Incremental: 77
App version : 1.0.3
java.lang.IllegalStateException
at android.media.MediaCodec.native_queueInputBuffer(Native Method)
at android.media.MediaCodec.queueInputBuffer(MediaCodec.java:2282)
at androidx.camera.core.VideoCapture.audioEncode(VideoCapture.java:753)
at androidx.camera.core.VideoCapture$1.run(VideoCapture.java:372)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
Similar question reference:https://stackoverflow.com/questions/59613877/fatal-exception-camerax-audio-encoding-thread
Is possibble to capture 1:1 ratio video?
The video recorded with a front-facing camera is flipped horizontally
横着或者倒着拍摄,拍摄的照片方向无法自动纠正。
Please update the project's Gradle version because we are unable to open the project, due to the following error:
An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin [id 'com.android.internal.version-check']
> Minimum supported Gradle version is 7.0.2. Current version is 6.1.1.
FAILURE: Build failed with an exception.
Where:
Build file '/home/Library/CameraXDemo-master/CameraXDemo/app/build.gradle' line: 1
What went wrong:
A problem occurred evaluating project ':app'.
Failed to apply plugin [id 'com.android.internal.version-check']
Minimum supported Gradle version is 6.5. Current version is 6.1.1. If using the gradle wrapper, try editing the distributionUrl in /home/Library/CameraXDemo-master/CameraXDemo/gradle/wrapper/gradle-wrapper.properties to gradle-6.5-all.zip
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 11s
I am testing the app on SM-T580 and while recording video the preview freezes and the video does not get recorded.
It gets frozen when record button is pressed. I believe this happening while the camera is autofocusing. If I wait for the camera to finish focusing and then press record button, it works as expected.
The app works perfectly fine on my other device where the camera has no autofocus function.
Is there a way to turn the autofocus off.
in android 11 flash on torch is not working
Hi,
I wonder if it is possible to use CameraX to access ToF (Time of Flight) sensor depth map.
Or should I use Camera2 ?
Thanks
i am capturing video from front video saved with flip. and please re implement camera with newer camerax lib
when i try to capture image below api level 29, its not capturing image
I have run your code image capture working fine but when i record video than it's not working video was not recorded and i didn't get any video thumbnail.
This demo is good! And how to access external cameras using Android cameraX? I know its cameraId, but only DEFAULT_BACK_CAMERA and DEFAULT_FRONT_CAMERA can be selected.
The picture always come before the video in the Preview library(gallery). Not in chronological order.
if we click on hdr and then click on exposure button it crash often
2024-02-05 11:52:31.040 18346-18346 AndroidRuntime com...ertlevonyan.demo.camerax E FATAL EXCEPTION: main
Process: com.robertlevonyan.demo.camerax, PID: 18346
java.lang.IllegalStateException: valueFrom(0.0) must be smaller than valueTo(0.0)
at com.google.android.material.slider.BaseSlider.validateValueFrom(BaseSlider.java:537)
at com.google.android.material.slider.BaseSlider.validateConfigurationIfDirty(BaseSlider.java:625)
at com.google.android.material.slider.BaseSlider.maybeCalculateTicksCoordinates(BaseSlider.java:1724)
at com.google.android.material.slider.BaseSlider.updateTrackWidth(BaseSlider.java:1745)
at com.google.android.material.slider.BaseSlider.onSizeChanged(BaseSlider.java:1715)
at android.view.View.sizeChange(View.java:25947)
at android.view.View.setFrame(View.java:25880)
at android.view.View.layout(View.java:25731)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:25737)
at android.view.ViewGroup.layout(ViewGroup.java:6818)
at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1873)
at android.view.View.layout(View.java:25737)
at android.view.ViewGroup.layout(ViewGroup.java:6818)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:25737)
at android.view.ViewGroup.layout(ViewGroup.java:6818)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:25737)
at android.view.ViewGroup.layout(ViewGroup.java:6818)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:25737)
at android.view.ViewGroup.layout(ViewGroup.java:6818)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:25737)
at android.view.ViewGroup.layout(ViewGroup.java:6818)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1891)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1729)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1638)
at android.view.View.layout(View.java:25737)
at android.view.ViewGroup.layout(ViewGroup.java:6818)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:25737)
at android.view.ViewGroup.layout(ViewGroup.java:6818)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1891)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1729)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1638)
at android.view.View.layout(View.java:25737)
at android.view.ViewGroup.layout(ViewGroup.java:6818)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:1075)
at android.view.View.layout(View.java:25737)
at android.view.ViewGroup.layout(ViewGroup.java:6818)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:5193)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4466)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:3239)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:11197)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1650)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1659)
at android.view.Choreographer.doCallbacks(Choreographer.java:1129)
at android.view.Choreographer.doFrame(Choreographer.java:1055)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1622)
at android.os.Handler.handleCallback(Handler.java:958)
2024-02-05 11:52:31.040 18346-18346 AndroidRuntime com...ertlevonyan.demo.camerax E at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8893)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
```at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
2021-04-06 13:42:06.758 29833-29833/com.robertlevonyan.demo.camerax E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.robertlevonyan.demo.camerax, PID: 29833
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.util.concurrent.ExecutionException: androidx.camera.core.InitializationException: java.lang.RuntimeException: Error retrieving camcorder profile params
at androidx.concurrent.futures.AbstractResolvableFuture.getDoneValue(AbstractResolvableFuture.java:518)
at androidx.concurrent.futures.AbstractResolvableFuture.get(AbstractResolvableFuture.java:475)
at androidx.concurrent.futures.CallbackToFutureAdapter$SafeFuture.get(CallbackToFutureAdapter.java:199)
at androidx.camera.core.impl.utils.futures.FutureChain.get(FutureChain.java:155)
at androidx.camera.core.impl.utils.futures.ChainingListenableFuture.get(ChainingListenableFuture.java:105)
at com.robertlevonyan.demo.camerax.fragments.CameraFragment$startCamera$1.run(CameraFragment.kt:325)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8506)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: androidx.camera.core.InitializationException: java.lang.RuntimeException: Error retrieving camcorder profile params
at androidx.camera.core.CameraX.lambda$initAndRetryRecursively$9$CameraX(CameraX.java:631)
at androidx.camera.core.-$$Lambda$CameraX$u-Xx2b6YXY5GXNXRh-mDiDnHdpQ.run(Unknown Source:10)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.RuntimeException: Error retrieving camcorder profile params
at android.media.CamcorderProfile.native_get_camcorder_profile(Native Method)
at android.media.CamcorderProfile.get(CamcorderProfile.java:456)
at androidx.camera.camera2.internal.Camera2DeviceSurfaceManager.lambda$E2rRrx9ASsJbpKoXo9ov4Zv64wI(Unknown Source:0)
at androidx.camera.camera2.internal.-$$Lambda$Camera2DeviceSurfaceManager$E2rRrx9ASsJbpKoXo9ov4Zv64wI.get(Unknown Source:0)
at androidx.camera.camera2.internal.SupportedSurfaceCombination.getRecordSize(SupportedSurfaceCombination.java:1213)
at androidx.camera.camera2.internal.SupportedSurfaceCombination.generateSurfaceSizeDefinition(SupportedSurfaceCombination.java:1168)
at androidx.camera.camera2.internal.SupportedSurfaceCombination.(SupportedSurfaceCombination.java:120)
at androidx.camera.camera2.internal.Camera2DeviceSurfaceManager.init(Camera2DeviceSurfaceManager.java:94)
at androidx.camera.camera2.internal.Camera2DeviceSurfaceManager.(Camera2DeviceSurfaceManager.java:82)
at androidx.camera.camera2.internal.Camera2DeviceSurfaceManager.(Camera2DeviceSurfaceManager.java:65)
at androidx.camera.camera2.Camera2Config.lambda$defaultConfig$0(Camera2Config.java:52)
at androidx.camera.camera2.-$$Lambda$Camera2Config$kPfcZYYQs2fXKvw1cjC5GhRy6hM.newInstance(Unknown Source:0)
at androidx.camera.core.CameraX.lambda$initAndRetryRecursively$9$CameraX(CameraX.java:578)
at androidx.camera.core.-$$Lambda$CameraX$u-Xx2b6YXY5GXNXRh-mDiDnHdpQ.run(Unknown Source:10)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
I have a samsung galaxy m10 with resolution 720 x 1520 pixels, 19:9 ratio.
Video recorded from camera is 1920 x 908.
When I'm using camerax, including your project - back camera is stretching and output video resolution is 1920 x 1080.
I need to use Camera2 instead, or it possible to fix on camerax?
Great Demo but there is a minor issue with saving files, even if all permissions are added the app wont save the capture.
Here is debug log:
E/CameraXDemo: Photo capture failed: Failed to write temp file
W/System.err: androidx.camera.core.ImageCaptureException: Failed to write temp file
at androidx.camera.core.ImageCapture$2.onError(ImageCapture.java:919)
W/System.err: at androidx.camera.core.ImageSaver.lambda$postError$2$ImageSaver(ImageSaver.java:319)
at androidx.camera.core.-$$Lambda$ImageSaver$q5J8WAquxyekKA6et-sNzW3OiJM.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
Caused by: java.io.FileNotFoundException: /storage/emulated/0/DCIM/CameraXDemo/CameraXec1baf11-03e1-4da7-be06-0194bc9e3f32.tmp (No such file or directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:308)
at java.io.FileOutputStream.<init>(FileOutputStream.java:238)
W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:180)
at androidx.camera.core.ImageSaver.saveImageToTempFile(ImageSaver.java:118)
at androidx.camera.core.ImageSaver.run(ImageSaver.java:85)
at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err: at java.lang.Thread.run(Thread.java:784)
D/OpenGLRenderer: HWUI Binary is enabled
D/OpenGLRenderer: HWUI Binary is enabled
I/GRALLOC: LockFlexLayout: baseFormat: 11, yStride: 1280, ySize: 921600, uOffset: 921600, uStride: 1280
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
Is there any possibility to add watermark to current recorded video
Hi thanks for this demo! However, when taking photo, it is not ensured that scene is focused. Therefore, users have to manually tap or wait to focus, before they can tap the "take photo" button. How can I solve this problem? Because it is quite annoying for users :/
I have a problem, with some devices won't start the camera,If I add about 30 more characters to the app id, the app won't work with some devices, If the app id has few characters, the camera works fine, is there any way to fix it
As fetcher is deprecated can you show me how to work with fetcherFactory to get video thumbnail.
Crash While record video switch front to back camera and back camera to the front camera thank you
Thank you for your awesome project.
I saw when I switching btw photo and video mode, camera going to black then turn on. How to make it keep playing?
I saw Twitter can do it without stop/start effect.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.