pvasa / cameraview-ex Goto Github PK
View Code? Open in Web Editor NEWEasy Android camera integration, advanced features.
License: Apache License 2.0
Easy Android camera integration, advanced features.
License: Apache License 2.0
Describe the bug
Tap focus does not work
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Tap Focus
Device (please complete the following information):
Branch Name (if using as a local module)
Describe the bug
When switching from front to rear or rear to front camera a crash occurs.
Code that causes the crash
camera.facing = when (camera.facing) { Modes.Facing.FACING_BACK -> Modes.Facing.FACING_FRONT else -> Modes.Facing.FACING_BACK }
Code causing the crash in Camera2.kt
config.autoFocus.value = Modes.DEFAULT_AUTO_FOCUS
Code that resolves the issue
config.autoFocus.postValue(Modes.DEFAULT_AUTO_FOCUS)
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Device (please complete the following information):
Additional context / stacktrace
E/AndroidRuntime: FATAL EXCEPTION: CameraViewExBackground Process: com.inthub.greenfly, PID: 1160 java.lang.IllegalStateException: Cannot invoke setValue on a background thread at androidx.lifecycle.LiveData.assertMainThread(LiveData.java:443) at androidx.lifecycle.LiveData.setValue(LiveData.java:286) at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:33) at com.priyankvasa.android.cameraviewex.CameraConfigLiveData.setValue$cameraViewEx_release(CameraConfigLiveData.kt:33) at com.priyankvasa.android.cameraviewex.Camera2.updateAf(Camera2.kt:949) at com.priyankvasa.android.cameraviewex.Camera2.updateModes(Camera2.kt:1028) at com.priyankvasa.android.cameraviewex.Camera2.access$updateModes(Camera2.kt:62) at com.priyankvasa.android.cameraviewex.Camera2$previewSessionStateCallback$1.onConfigured(Camera2.kt:144) at java.lang.reflect.Method.invoke(Native Method) at android.hardware.camera2.dispatch.InvokeDispatcher.dispatch(InvokeDispatcher.java:39) at android.hardware.camera2.dispatch.HandlerDispatcher$1.run(HandlerDispatcher.java:65) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.os.HandlerThread.run(HandlerThread.java:65)
Branch Name (if using as a local module)
Hello,
Finally i set like this:
cameraView.setCameraMode(Modes.CameraMode.VIDEO_CAPTURE);
cameraView.enableCameraMode(Modes.CameraMode.VIDEO_CAPTURE);
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/cubeTok");
myDir.mkdirs();
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new
Date());
String fname = "cubeTok_" + timeStamp + ".mp4";
File file = new File(myDir, fname);
cameraView.startVideoRecording(file);
But it's give an Exception:
"com.priyankvasa.android.cameraviewex.CameraViewException: Unable to start
video recording.
Is there anything lake to put? Please me to solve this.
Thanks.
Describe the bug
The latest batch of changes merged into developed has introduced an issue. If you launch your CameraActivity from another activity, then leave the camera, go back and forth a few times eventually it all locks up.
I have provided a simple activity that I used to reproduce the issue off of the development branch. When I switch to my fork that does not have your latest changes I am able to open the camera as many times as I want without issue.
To Reproduce
Pull request that demonstrates the issue:
#118
Expected behavior
Before the latest batch of changes the issue did not occur.
Using ProGuard
Device (please complete the following information):
I'm trying to process frames in
camera.setPreviewFrameListener { image: Image -> /* Preview frame available. */ }
I managed to convert them to Bitmap however I'm having problems with rotation of the output images. I need to get the CameraCharacteristics.SENSOR_ORIENTATION
irrelevant to device orientation to perform successful rotation.
As a workaround I do it now independently by calling manager.getCameraCharacteristics(cameraId).get(CameraCharacteristics.SENSOR_ORIENTATION)
. Note cameraId
is set manually as I could not find any way to get it from CameraView
.
Please provide a clean way to get CameraCharacteristics.SENSOR_ORIENTATION
.
I am getting this error when compiling now
jetified-cameraview-ex-3.5.5-alpha\res\values\values.xml: AAPT: error: expected enum but got (raw string) single_capture.
I'm working on merging the latest dev branch into my fork and to also integrate it in with my fork's changes. I've encountered a question that I think you can clear up. Was the root sampleApp project refactored into CameraEx/sampleApp?
I can't figure out how to get it to build the CameraEx/sampleApp in Android Studio 3.3.2. cameraViewEx and sampleAppJava show up as projects.
I tried adding it into settings.gradle.kts:
include(":cameraViewEx", ":sampleAppJava")
include(":CameraEx")
Update I tried with this and then it shows up as a module that can be built, but fails to build.
include(":CameraEx:sampleApp")
ERROR: Failed to resolve: com.priyankvasa.android:cameraview-ex:3.4.3-debug
Show in Project Structure dialog
Affected Modules: sampleApp
Probably this should reference the local project instead of a remote dependency?
implementation("com.priyankvasa.android:cameraview-ex:3.4.3-debug")
Describe the bug
I use the library only to take pictures and the permission RECORD_AUDIO is automatically added to the manifest.
Is there a way to avoid this permission to be added ?
stopVideoRecording()
always returns false, with no error
private var tmpVideoFile: File? = null
@SuppressLint("SimpleDateFormat")
@Throws(IOException::class)
private fun getNewVideoFile(): File {
// Create an image file name
val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date())
val directory = "${Environment.getExternalStorageDirectory().absolutePath}/filmit/videos".also { File(it).mkdirs() }
return File(directory, "$timeStamp.mp4")
}
@SuppressLint("MissingPermission")
private fun listenToVideoRecordEvent() {
publisherDisposable = videoRecordEventPublisher.subscribe {
if (it) {
recordVideoFrame.visibility = View.VISIBLE
tmpVideoFile = getNewVideoFile()
recordVideoCamera.startVideoRecording(tmpVideoFile!!) {
// Configure video (MediaRecorder) parameters
audioEncoder = AudioEncoder.Aac
videoFrameRate = 60
videoStabilization = true
videoEncoder = VideoEncoder.H263
}
} else {
if(recordVideoCamera.stopVideoRecording()) {
uploadTmpVideo()
} else {
Log.e(TAG, "failed to save video to file")
Log.d(TAG, tmpVideoFile.toString())
}
recordVideoFrame.visibility = View.GONE
}
}
}
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
In the latest 3.0.1 beta it looks like camera.cameraMode
has been replaced with camera.setCameraMode(int)
. Is there some other mechanism to get the current camera mode or is it now up to the client to keep a reference to which mode the camera is in?
Maybe I could add a getter into CameraView.kt
fun getCameraMode() : Int {
return config.cameraMode.value
}
Describe the bug
I have get much crash with Error opening camera with id 0
Using ProGuard
YES
Screenshots
If applicable, add screenshots to help explain your problem.
Device (please complete the following information):
Additional context / stacktrace
Fatal Exception: com.priyankvasa.android.cameraviewex.CameraViewException: Error opening camera with id 0 (error: 4)
at com.priyankvasa.android.cameraviewex.Camera2$cameraDeviceCallback$2$1.onError(Camera2.java:62)
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.notifyError(CameraDeviceImpl.java:1922)
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.lambda$Sm85frAzwGZVMAK-NE_gwckYXVQ(CameraDeviceImpl.java)
at android.hardware.camera2.impl.-$$Lambda$CameraDeviceImpl$CameraDeviceCallbacks$Sm85frAzwGZVMAK-NE_gwckYXVQ.accept(-.java:8)
at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:258)
at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:182)
at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:77)
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.os.HandlerThread.run(HandlerThread.java:65)
The camera just freezes when shooting with FLASH_ON and after a small moment this error comes out
2019-09-26 03:38:21.827 17385-17385/com.waynyo.debug E/CameraFragment$onCreateView: com.priyankvasa.android.cameraviewex.CameraViewException: Error opening camera with id 0 (error: 4)
at com.priyankvasa.android.cameraviewex.Camera2$cameraDeviceCallback$2$1.onError(Camera2.kt:145)
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.notifyError(CameraDeviceImpl.java:1929)
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.lambda$Sm85frAzwGZVMAK-NE_gwckYXVQ(Unknown Source:0)
at android.hardware.camera2.impl.-$$Lambda$CameraDeviceImpl$CameraDeviceCallbacks$Sm85frAzwGZVMAK-NE_gwckYXVQ.accept(Unknown Source:8)
at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:258)
at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:182)
at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:77)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.os.HandlerThread.run(HandlerThread.java:65)
Steps to reproduce the behavior:
Expected behavior
Give the image correctly with no freezes
Using ProGuard
Screenshots
If applicable, add screenshots to help explain your problem.
Device (please complete the following information):
Describe the bug
Deploying an app that depends on this library to the Google Play Store renders the app unsupported on ALL Android devices. Removing the library as a dependency and any references to it in the code resolves the issue. According to the Google Play Store, 0 devices are supported due to the following issue:
This doesn't make sense since:
Doesn't support required feature <uses-feature> - android.hardware.camera2
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Devices should be supported, none are.
Using ProGuard
Screenshots
Attached
Device (please complete the following information):
Additional context / stacktrace
N/A
Branch Name (if using as a local module)
Any idea what we could be doing wrong? The error we receive from the Play Store seems to be misleading.
Can you point me in the right direction on how to set the aspect ratio for capturing an image with Camera2? The equivalent of setPictureSize on Camera1. I would like to do something similar to what we did with videos and allow taking photos in 4:3 or 16:9. Currently with a full screen preview the captured image is 4:3.
Describe the bug
Capture doesn't work after stopping and restarting the camera in release 2.7.0. An error is not generated and the picture taken listener is not invoked. This showed up in this latest release (2.7.0), it doesn't seem to occur on 2.6.1.
To Reproduce
Steps to reproduce the behavior:
start
stop(false)
start
capture
and the dimming UI animation occurs but addPictureTakenListener
or addCameraErrorListener
are never calledExpected behavior
Calling capture should call either the error listener or the picture taken listener.
Using ProGuard
Device (please complete the following information):
Branch Name (if using as a local module)
Black preview while front-facing
When we keep facing value as "front", it is giving black preview.
To Reproduce
Just keep facing to front in xml value.
Expected behavior
Front camers preview instead of black screen.
If anyone has faced this kind of issue please help me.
Thanks.
Fatal Exception: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. at android.view.ViewGroup.addViewInner(ViewGroup.java:4471) at android.view.ViewGroup.addView(ViewGroup.java:4312) at android.view.ViewGroup.addView(ViewGroup.java:4252) at android.view.ViewGroup.addView(ViewGroup.java:4225) at com.priyankvasa.android.cameraviewex.PreviewImpl.markTouchAreas$cameraViewEx_release(PreviewImpl.kt:85) at com.priyankvasa.android.cameraviewex.Camera2$previewSurfaceTappedListener$2$1.invoke(Camera2.kt:529) at com.priyankvasa.android.cameraviewex.Camera2$previewSurfaceTappedListener$2$1.invoke(Camera2.kt:70) at com.priyankvasa.android.cameraviewex.TextureViewPreview$$special$$inlined$apply$lambda$2.invoke(TextureViewPreview.kt:66) at com.priyankvasa.android.cameraviewex.TextureViewPreview$$special$$inlined$apply$lambda$2.invoke(TextureViewPreview.kt:34) at com.priyankvasa.android.cameraviewex.SurfaceTouchListener$tapGestureListener$1.onSingleTapConfirmed(SurfaceTouchListener.kt:46) at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:303) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:156) at android.app.ActivityThread.main(ActivityThread.java:6523) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
Describe the bug
9/12/19 Update:
I was totally incorrect about what was going on. The ZTE Cymbal T runs android 5 but when it tries to use Camera2 it is falling back to Camera1. This issue here is with Camera1 and not Camera2. I have also validated that the Camera2 functionality works perfectly on a Nexus 6, only when using Camera1 is it upside down. Because of this I consider it a much lower of a priority.
Some devices have cameras installed in the device in non-standard orientations, usually with the front camera (selfie). Examples are some of the Nexus 5/6 devices and a test device I have, ZTE Cymbal T. The issue here is only with Camera1 and only with the preview. The recorded video is in the correct orientation.
I did some tests forcing the camera into Camera1 and then tested the fix on the broken device and on a device that did not have the problem.
Steps performed:
With my changes in place : #209
ZTE Cymbal T: Camera locked in portrait
Xaiomi: Camera locked in portrait
Try it out on a few devices forcing the camera to use Camera1 and see if it also works correctly for you.
Device (please complete the following information):
Describe the bug
when run camera.start(), app crash.
Additional context / stacktrace
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.leyan.app, PID: 5597
java.lang.VerifyError: com/priyankvasa/android/cameraviewex/VideoManager
at com.priyankvasa.android.cameraviewex.Camera1$videoManager$2.invoke(Camera1.kt:88)
at com.priyankvasa.android.cameraviewex.Camera1$videoManager$2.invoke(Camera1.kt:48)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.priyankvasa.android.cameraviewex.Camera1.getVideoManager(Camera1.kt)
at com.priyankvasa.android.cameraviewex.Camera1.isVideoRecording(Camera1.kt:186)
at com.priyankvasa.android.cameraviewex.CameraInterface$DefaultImpls.stop(CameraInterface.kt:62)
at com.priyankvasa.android.cameraviewex.Camera1.stop(Camera1.kt:337)
at com.priyankvasa.android.cameraviewex.CameraView.stop(CameraView.kt:660)
at com.leyan.app.domain.main.MainActivity.onPause(MainActivity.kt:68)
at android.app.Activity.performPause(Activity.java:5335)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1233)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3034)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3003)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2981)
at android.app.ActivityThread.access$1000(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
at dalvik.system.NativeStart.main(Native Method)
Branch Name (if using as a local module)
3.5.4-alpha
Describe the bug
Front facing camera doesn't fire addPictureTakenListener event
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Save Image from addPictureTakenListener
Using ProGuard
Screenshots
n/a
Device: Not OK
Device OK:
Branch Name (if using as a local module)
Describe the bug
The setOnPreviewFrameListener
method on CameraView
is not getting any callback.
To Reproduce
Steps to reproduce the behavior:
cameraView.setOnPreviewFrameListener {..}
Expected behavior
The listener is invoked when camera preview is on
Using ProGuard
Screenshots
N/A
Device (please complete the following information):
Additional context / stacktrace
N/A
Branch Name (if using as a local module)
I just want to take a single image without user interaction and without displaying a view. Is this possible? If not with this library, is it possible at all with the Camera2 API?
Describe the bug
Upgraded project to AndroidX and camera no longer works as expected.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Should work as expected and not crash.
Using ProGuard
Device (please complete the following information):
Additional context / stacktrace
Caused by: java.lang.IllegalStateException: Cannot invoke observe on a background thread at androidx.lifecycle.LiveData.assertMainThread(LiveData.java:443) at androidx.lifecycle.LiveData.observe(LiveData.java:171) at com.priyankvasa.android.cameraviewex.CameraConfigLiveData.observe$cameraViewEx_release(CameraConfigLiveData.kt:46) at com.priyankvasa.android.cameraviewex.Camera2.addObservers(Camera2.kt:490) at com.priyankvasa.android.cameraviewex.Camera2.<init>(Camera2.kt:82) at com.priyankvasa.android.cameraviewex.Camera2Api23.<init>(Camera2Api23.kt:32) at com.priyankvasa.android.cameraviewex.Camera2Api24.<init>(Camera2Api24.kt:31) at com.priyankvasa.android.cameraviewex.CameraView$camera$1.invokeSuspend(CameraView.kt:115) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32) at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:236) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594) at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742))
Good day sir. I am a graphic designer and i am interested in designing a logo for your good project. I will be doing it as a gift for free. I just need your permission first before I begin my design. Hoping for your positive feedback. Thanks
My use cases required to Preview, Record and Process the frames simultaneously, I have used this codebase, It seems promising but it's still, not supporting recording and frame processing at the same time. It would be nice if you can incorporate the same if you have some time.
Hi, how i cad add listener for automatic focus without set points on startAutofocus?
Hi. In Android camera 2 API there is implementation levels, I couldn't find any way, for checking implementation level. So how I can get implementation level?
Describe the bug
A clear and concise description of what the bug is.
Related to #96 - Same error, different scenario. I've tried using a version with the fix in that issue applied but am still running into this issue.
To Reproduce
Steps to reproduce the behavior:
-Starting the camera from onRequestPermissionsResult
(even if using runOnUIThread
) results in a crash due to setValue
being called on a background thread. After allowing the permissions, the app crashes. The next launch of the camera (that doesn't happen in onRequestPermissionResult but in onResume) seems to be fine.
Expected behavior
Camera should start without causing a crash.
Using ProGuard
Device (please complete the following information):
Additional context / stacktrace
019-01-15 16:25:32.573 24540-24638/com.speakezyapp.speakezyclient E/AndroidRuntime: FATAL EXCEPTION: CameraViewExBackground Process: com.speakezyapp.speakezyclient, PID: 24540 java.lang.IllegalStateException: Cannot invoke setValue on a background thread at androidx.lifecycle.LiveData.assertMainThread(LiveData.java:443) at androidx.lifecycle.LiveData.setValue(LiveData.java:286) at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:33) at com.priyankvasa.android.cameraviewex.CameraConfigLiveData.setValue$cameraViewEx_release(CameraConfigLiveData.kt:33) at com.priyankvasa.android.cameraviewex.Camera2.updateOis(Camera2.kt:1010) at com.priyankvasa.android.cameraviewex.Camera2.access$updateOis(Camera2.kt:63) at com.priyankvasa.android.cameraviewex.Camera2$addObservers$$inlined$run$lambda$11.invoke(Camera2.kt:583) at com.priyankvasa.android.cameraviewex.Camera2$addObservers$$inlined$run$lambda$11.invoke(Camera2.kt:63) at com.priyankvasa.android.cameraviewex.CameraConfigLiveData$observe$1.onChanged(CameraConfigLiveData.kt:47) at androidx.lifecycle.LiveData.considerNotify(LiveData.java:113) at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:126) at androidx.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:424) at androidx.lifecycle.LiveData$LifecycleBoundObserver.onStateChanged(LiveData.java:376) at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:355) at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:293) at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:333) at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:138) at androidx.lifecycle.LifecycleRegistry.markState(LifecycleRegistry.java:111) at com.priyankvasa.android.cameraviewex.Camera2.startPreviewCaptureSession(Camera2.kt:897) at com.priyankvasa.android.cameraviewex.Camera2.access$startPreviewCaptureSession(Camera2.kt:63) at com.priyankvasa.android.cameraviewex.Camera2$cameraDeviceCallback$1.onOpened(Camera2.kt:117) at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:139) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.os.HandlerThread.run(HandlerThread.java:65)
Camera Settings Applied
<com.priyankvasa.android.cameraviewex.CameraView android:id="@+id/create_post_camera" android:layout_width="match_parent" android:layout_height="match_parent" android:adjustViewBounds="true" android:keepScreenOn="true" app:aspectRatio="4:3" app:autoFocus="continuous_picture" app:awb="auto" app:cameraMode="single_capture" app:facing="back" app:flash="auto" app:jpegQuality="high" app:noiseReduction="high_quality" app:opticalStabilization="true" app:outputFormat="jpeg" app:pinchToZoom="true" app:shutter="short_time" app:touchToFocus="true" app:zsl="true" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" />
Only other interaction with the library is to set the camera mode and addPictureTakenListener
in onCreate
. Let me know if any other information or data would help.
Branch Name (if using as a local module)
Hey @pvasa I have the camera in a fragment of a viewpager and have started and stopped the camera in onResume and onPause methods of the fragment. In some cases on start call getting a crash -
Adding the stacktrace -
Fatal Exception: java.util.NoSuchElementException: Sequence is empty.
at kotlin.sequences.SequencesKt___SequencesKt.last(_Sequences.kt:202)
at com.priyankvasa.android.cameraviewex.extension.SortedSetExtensionsKt$chooseOptimalPreviewSize$2.invokeSuspend(SortedSetExtensions.kt:44)
at com.priyankvasa.android.cameraviewex.extension.SortedSetExtensionsKt$chooseOptimalPreviewSize$2.invoke(Unknown Source:10)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:84)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:142)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
at com.priyankvasa.android.cameraviewex.extension.SortedSetExtensionsKt.chooseOptimalPreviewSize(SortedSetExtensions.kt:33)
at com.priyankvasa.android.cameraviewex.Camera2$startPreviewCaptureSession$2.invokeSuspend(Camera2.kt:858)
at com.priyankvasa.android.cameraviewex.Camera2$startPreviewCaptureSession$2.invoke(Unknown Source:10)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:84)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:142)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
at com.priyankvasa.android.cameraviewex.Camera2.startPreviewCaptureSession(Camera2.kt:850)
at com.priyankvasa.android.cameraviewex.Camera2$1$1.invokeSuspend(Camera2.kt:80)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:236)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)
Before I start adding this in I wanted to make sure it is not already available and I have missed it.
Current functionality:
The user can get the list of valid aspect ratios and set one, example 16:9.
When the recording starts a video size is automatically chosen by the closest size to the screen preview and the selected aspect ratio.
Example: On a LG G6 set at 16:9 using a full screen preview this results in a 2560x1440 video.
Enhancement:
Example: On a LG G6 set at 16:9 be able to record in 1900x1080 or 1280x720
On the latest 3.0.1-beta I have been experiencing crashes if I leave the activity and then come back. I have not taken the time to try to reproduce it from the sample app yet. I wanted to see if this is already resolved in any upcoming updates.
java.lang.IllegalStateException: CameraDevice was already closed
at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:2266)
at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1007)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.stopRepeating(CameraCaptureSessionImpl.java:281)
at com.priyankvasa.android.cameraviewex.Camera2.releaseCaptureSession(Camera2.kt:676)
at com.priyankvasa.android.cameraviewex.Camera2.setAspectRatio(Camera2.kt:696)
at com.priyankvasa.android.cameraviewex.CameraView$1.invoke(CameraView.kt:214)
at com.priyankvasa.android.cameraviewex.CameraView$1.invoke(CameraView.kt:47)
at com.priyankvasa.android.cameraviewex.CameraConfigLiveData$observe$1.onChanged(CameraConfigLiveData.kt:46)
I updated Camera2.kt and added a try/catch as a test. Afterwards the app no longer crashed and the camera is working good when leaving and returning.
private fun releaseCaptureSession() {
captureSession?.run {
try {
stopRepeating()
abortCaptures()
close()
} catch (e : Exception) {
println("Error e=" + e.message)
}
}
captureSession = null
}
Description
When using a custom size for CameraView, the preview (TextureView) expands out of bounds of CameraView and produces images of size of preview instead of CameraView.
To Reproduce
Steps to reproduce the behavior:
width = 720
and height = 540
cameraView.start()
Expected behavior
The TextureView is bound by and of same size of CameraView
Actual behavior
The TextureView size is 720x960 which is still 4:3 ratio but not what is expected
Using ProGuard
Device:
Branch Name (if using as a local module)
Got this complie error when running project:
error: expected boolean but got (raw string) continuous_picture.
Execution failed for task ':app:processDebugResources'.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
Android resource linking failed
AAPT: AndroidStudioProjects\Blah\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:4684: error: expected enum but got (raw string) single_capture.
error: failed linking references.
How do i resolve this issue ? please help
App does extra flash when getting out of camera
Steps to reproduce the behavior:
Actual behavior
You will see that an extra flash occurs
Expected behavior
When pressed back, it should not flash
Hi. I have tried to take picture on emulator, it's not working!
Describe the bug
Unable to build project when library is added. Getting the following error message
/app/build/intermediates/incremental/mergeFreemiumDebugResources/merged.dir/values/values.xml:6167: error: expected boolean but got (raw string) continuous_picture.
When I open the values.xml file the problem seems to be caused by the following line:
<item name="autoFocus">continuous_picture</item>
When I start record video on some devices with aspect ratio 9:16 I got error:
com.priyankvasa.android.cameraviewex.CameraViewException: Unable to start video recording.
java.lang.IllegalArgumentException: Surface was abandoned.
It failed for Huawei P30 Lite
it works fine for Samsung S8
Hi
I'm using this library for recording videos and it's not working as expected in OnePlus6 Android 10.
I don't have another Android 10 issue to test but I believe it's Android 10 issue and not specific to OnePlus 6.
When I click on the RecordVideo button, the listeners are not set
fun addVideoRecordStartedListener(listener: () -> Unit): CameraView { listenerManager.videoRecordStartedListeners.add(listener) return this }
The above listener doesn't work. I can say that because the Button doesn't change to Active state.
And the camera.IsVideoRecording always stays false. Though the camera starts recording.
I tested it on another Android device Vivo Android 9. And it works as expected.
Basic configuration of camera view does not start on some devices.
On android 9 One Plus 6 it works as it should (starting preview)
on Lenovo Yoga tab 3 Android 7.1 (api 25) and on samsung Samsung Sm-A500FU android 6.0.1 (api 23) CameraView falls into some strange behaviour and does nothing,
in ovveriden method Camera2.start() it returns false and just hang there. In detail method chooseCameraIdByFacing() returns false so the true value from start is returned from line 626.
I have no idea why that is happening. Tested on both version 2.8.1 and 3.0.1-beta.
Basic Camera 2 api apps works on both devices.
CameraView widget has standart style from style="@style/Widget.CameraView"
@pvasa
Describe the bug
A crash on cameraview start on multiple number of devices in camera1.Starting the camera on onResume of fragment and stopping it in onPause.
To Reproduce
Crash occurs when closing the app and relaunching it.
Expected behavior
Camera should close with normal backpress app close and restart on app launch.
Using ProGuard
Yes
Device (please complete the following information):
Additional context / stacktrace
Fatal Exception: java.lang.VerifyError: com/priyankvasa/android/cameraviewex/VideoManager
at com.priyankvasa.android.cameraviewex.Camera1$videoManager$2.invoke(Camera1.kt:69)
at com.priyankvasa.android.cameraviewex.Camera1$videoManager$2.invoke(Camera1.kt:43)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.priyankvasa.android.cameraviewex.Camera1.getVideoManager(Camera1.kt)
at com.priyankvasa.android.cameraviewex.Camera1.isVideoRecording(Camera1.kt:127)
at com.priyankvasa.android.cameraviewex.CameraInterface$DefaultImpls.stop(CameraInterface.kt:45)
at com.priyankvasa.android.cameraviewex.Camera1.stop(Camera1.kt:250)
at com.priyankvasa.android.cameraviewex.CameraView.stop(CameraView.kt:564)
at com.anurag.videous.fragments.defaults.camera.CameraFragment.onPause(CameraFragment.java:422)
at android.support.v4.app.Fragment.performPause(Fragment.java:2645)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1512)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
at android.support.v4.app.FragmentManagerImpl.dispatchPause(FragmentManager.java:3245)
at android.support.v4.app.Fragment.performPause(Fragment.java:2641)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1512)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
at android.support.v4.app.FragmentManagerImpl.dispatchPause(FragmentManager.java:3245)
at android.support.v4.app.FragmentController.dispatchPause(FragmentController.java:234)
at android.support.v4.app.FragmentActivity.onPause(FragmentActivity.java:476)
at com.core.activities.base.BaseActivityView.onPause(BaseActivityView.java:109)
at com.core.activities.landing.LandingActivity.onPause(LandingActivity.java:433)
at android.app.Activity.performPause(Activity.java:5546)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1240)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3324)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3293)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3271)
at android.app.ActivityThread.access$1000(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(NativeStart.java)
first time install this sample application and then after ask the permission and after press the allow button so next step in always show white screen . (i am using android 6.0 old device)
Describe the bug
Hello. I'm using your very nice to use Camera API in an activity with android:screenOrientation="portrait".
When i start in portrait orientation and switch the camera after I've rotated the device to landscape orientation the preview ist totally stretched and wrong rotated.
To Reproduce
Expected behavior
A non streched camera preview aber switching the camera
Using ProGuard
Screenshots
Device in portrait mode works very good!
Device rotated to landscape and camera switch twice (to front and again to back camera)
I'm using the Version 3.4.3
Want to raise 2 points:
First is that the callbacks of the library are using kotlin and prefer lambda expressions. The code is not designed to work well with java 7. For example: camera.addCameraOpenedListener()
Please mention this in prerequisite to use this library, or provide support/guide for using it along with Java 7.
Second,
After adding library dependency, got error during build:
More than one file was found with OS independent path 'META-INF/atomicfu.kotlin_module'
Expected behavior
Build should work without causing conflicts.
Using ProGuard
Device (please complete the following information):
To fix this, had to add following in app level gradle:
packagingOptions {
pickFirst 'META-INF/*'
}
Any reason why this is happening?
My dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// request permission
implementation 'com.karumi:dexter:6.0.1'
// CameraViewEx
// https://github.com/pvasa/cameraview-ex?utm_source=android-arsenal.com&utm_medium=referral&utm_campaign=7320
implementation "com.priyankvasa.android:cameraview-ex:3.5.5-alpha"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Currently in order to record a landscape video you have to leave the orientation unlocked. This results in a jarring experience when the device changes from portrait to landscape. A better approach would be to allow the device to be fixed to portrait or userPortrait. When the recording or picture is taken it would be taken in the correct orientation based on the device orientation.
Setting the activity to android:screenOrientation="userPortrait"
locks the orientation but videos and images are taken in portrait even when rotated to landscape.
For Camera1 you would use camera.setDisplayOrientation, which is already being done in Camera1.kt.
For Camera2 I though it was supposed to just work by default since there is no setDisplayOrientation. However, it is not working.
I will start looking into how this is supposed to work and see if I can come up with a fix. If you have any tips they would be welcomed.
Is your feature request related to a problem? Please describe.
How to be silent or without AudioSource when recording video by front camera, because I wanna record audio by another tool for an evaluation. THX!
Describe the solution you'd like
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Hello,
I'm beginner of android developer. I'm using this library because more interesting to integrate and easy.
But how can i start to video recording like as capture Image ?
Like it's easy coding to capture image
cameraView.setCameraMode(Modes.CameraMode.SINGLE_CAPTURE);
cameraView.enableCameraMode(Modes.CameraMode.SINGLE_CAPTURE);
cameraView.capture();
but there is no single syntax for video recording..
cameraView.setCameraMode(Modes.CameraMode.VIDEO_CAPTURE);
cameraView.enableCameraMode(Modes.CameraMode.VIDEO_CAPTURE);
cameraView.captureVideo();
Please! help me.
Thanks.
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.