GithubHelp home page GithubHelp logo

pvasa / cameraview-ex Goto Github PK

View Code? Open in Web Editor NEW
229.0 10.0 49.0 1.4 MB

Easy Android camera integration, advanced features.

License: Apache License 2.0

Kotlin 58.33% RenderScript 0.19% Java 41.49%
camera camera-library cameraview android kotlin kotlin-android kotlin-library android-library camera-api camera2-api

cameraview-ex's People

Contributors

pcm2a avatar pvasa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cameraview-ex's Issues

Tap focus does not work

Describe the bug
Tap focus does not work

To Reproduce
Steps to reproduce the behavior:

  1. Add 'app:touchToFocus="true"' Inyo xml file
  2. Tap on screen and focus not working

Expected behavior
Tap Focus

Device (please complete the following information):

  • Device: Redmi Mi A1
  • OS: Android ( 9.0)
  • API: API 28

Branch Name (if using as a local module)

  • master
  • development
  • release
  • other (please specify)

config.autoFocus.value causes crash when switching cameras

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:

  1. Use the latest version of cameraview-ex from master
  2. Run a sample activity that allows switching the camera
  3. Experience the crash

Expected behavior
A clear and concise description of what you expected to happen.

Device (please complete the following information):

  • Device: LG G6
  • OS: 8.0

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)

  • master

Exception at Video recording

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.

Crash if launching CameraActivity multiple times

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

  1. Have an activity that you launch the camera from
  2. Go back out of the camera
  3. Go in and out of the camera a few times and it will fail

Expected behavior
Before the latest batch of changes the issue did not occur.

Using ProGuard

  • with ProGuard
  • [X ] without ProGuard

Device (please complete the following information):

  • Device: LG G6
  • OS: 8.0
  • App version [2.7.0]

Provide access to CameraCharacteristics.SENSOR_ORIENTATION

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.

Was sampleApp moved to CameraEx/sampleApp?

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")

https://imgur.com/a/gOn8to4

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")

Library automatically adds RECORD_AUDIO

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 ?

Video recording fails to save to file

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
      }
    }

  }

Camera1 Video Recording Support Or Throw Not Supported Exception

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.

How to get the cameraMode in 3.0.1 beta?

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
}

[crash] Error opening camera with id 0

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):

  • Device: [Huawei Honor V20]
  • OS: [Android 9.0]

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)

Camera freeze when shooting with flash

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:

  1. set FLASH_ON
    2.Shoot with the camera

Expected behavior
Give the image correctly with no freezes

Using ProGuard

  • without ProGuard

Screenshots
If applicable, add screenshots to help explain your problem.

Device (please complete the following information):

  • Device: Galaxy Note 9
  • OS: Android 9
  • API: 28

0 supported devices when deploying to Google Play Store

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:
Screen Shot 2019-06-28 at 1 58 54 AM

This doesn't make sense since:

  1. Devices that do support camera2 are still showing as unsupported with the same error.
  2. We've included this in our AndroidManifest.xml file:
    Doesn't support required feature <uses-feature> - android.hardware.camera2
    This is to ensure that devices that do not support camera2 will still work.

To Reproduce
Steps to reproduce the behavior:

  1. Upload APK to Google Play Store
  2. Check supported devices

Expected behavior
Devices should be supported, none are.

Using ProGuard

  • with ProGuard
  • without ProGuard

Screenshots
Attached

Device (please complete the following information):

  • All devices are impacted

Additional context / stacktrace
N/A

Branch Name (if using as a local module)

  • master
  • development
  • release
  • other (please specify)

Any idea what we could be doing wrong? The error we receive from the Play Store seems to be misleading.

How to capture images in 16:9

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.

Capture fails after a restart of the camera

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:

  1. Start camera using start
  2. Stop camera using stop(false)
  3. Start camera again using start
  4. Call capture and the dimming UI animation occurs but addPictureTakenListener or addCameraErrorListener are never called

Expected behavior
Calling capture should call either the error listener or the picture taken listener.

Using ProGuard

  • with ProGuard
  • without ProGuard

Device (please complete the following information):

  • Device: S8+
  • OS: 8.0.0
  • API: 27
  • App version 0.1

Branch Name (if using as a local module)

  • master
  • development
  • release
  • other (please specify)

When we keep facing to front, it is giving black screen preview.

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.

IllegalStateException The specified child already has a parent. You must call removeView() on the child's parent first. com.priyankvasa.android.cameraviewex.PreviewImpl.markTouchAreas$cameraViewEx_release

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)

Camera1 preview wrong orientation on some devices

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:

  1. Holding phone portrait, back camera:
  2. Holding phone portrait, switch to selfie camera:
  3. Rotate phone to landscape, switch to back camera
  4. Holding phone in landscape: switch to selfie camera:

With my changes in place : #209

ZTE Cymbal T: Camera locked in portrait

  1. deviceRotation=0, WindowManager.rotation=0, getCameraDegrees()=0, displayOrientation=90
  2. deviceRotation=0, WindowManager.rotation=0, getCameraDegrees()=0, displayOrientation=270
  3. deviceRotation=90, WindowManager.rotation=0, getCameraDegrees()=0, displayOrientation=90
  4. deviceRotation=90, WindowManager.rotation=0, getCameraDegrees()=0, displayOrientation=270

Xaiomi: Camera locked in portrait

  1. rotationDegrees=0, WindowManager.rotation=0, getCameraDegrees()=0, displayOrientation=90
  2. rotationDegrees=0, WindowManager.rotation=0, getCameraDegrees()=0, displayOrientation=90
  3. rotationDegrees=90, WindowManager.rotation=0, getCameraDegrees()=0, displayOrientation=90
  4. rotationDegrees=90, WindowManager.rotation=0, getCameraDegrees()=0, displayOrientation=90

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):

  • Device: ZTE Cymbal T
  • OS: Android 5.1

crash in android4.4

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

Front facing camera doesn't fire addPictureTakenListener event

Describe the bug
Front facing camera doesn't fire addPictureTakenListener event

To Reproduce
Steps to reproduce the behavior:

  1. Set camera to front facing
  2. Call camera.capture()
  3. The addPictureTakenListener does not fire
  4. When camera is set to Back, it works fine and I'm able to save the image

Expected behavior
Save Image from addPictureTakenListener

Using ProGuard

  • with ProGuard

Screenshots
n/a

Device: Not OK

  • Device: [Google Pixel 2]
  • OS: [Android Pie (9.0)]
  • Nexus 5x device [ Android Oreo]

Device OK:

  • Device: [Samsung Tab 2] Android 7.0

Branch Name (if using as a local module)

  • master

setOnPreviewFrameListener not getting any callback

Describe the bug
The setOnPreviewFrameListener method on CameraView is not getting any callback.

To Reproduce
Steps to reproduce the behavior:

  1. Add a listener with cameraView.setOnPreviewFrameListener {..}

Expected behavior
The listener is invoked when camera preview is on

Using ProGuard

  • with ProGuard
  • without ProGuard

Screenshots
N/A

Device (please complete the following information):

  • Device: Samsung S8
  • OS: Android Oreo (8.0)
  • API: API 26
  • App version 2.0.0

Additional context / stacktrace
N/A

Branch Name (if using as a local module)

  • master
  • development
  • release
  • other (please specify)

Can a single image be taken without the view?

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?

Upgraded app to AndroidX causes crash

Describe the bug
Upgraded project to AndroidX and camera no longer works as expected.

To Reproduce
Steps to reproduce the behavior:

  1. Open up a screen that uses the camera

Expected behavior
Should work as expected and not crash.

Using ProGuard

  • with ProGuard
  • without ProGuard

Device (please complete the following information):

  • Google Pixel 2
  • Android 8.1
  • 27

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))

New logo/icon proposal

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

Video recording and Frame processing simultaneously

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.

Auto focus listener

Hi, how i cad add listener for automatic focus without set points on startAutofocus?

Camera.start causing crash intermittently

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

  • with ProGuard
  • without ProGuard

Device (please complete the following information):

  • Device: S8+
  • OS: 8.0.0
  • API: 27
  • App version 0.1

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)

  • master
  • development
  • release
  • other (please specify)

Crash on camera start(NoSuchElementException)

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)

Setting the video size to record in

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:

  • The ability to get the available video sizes for the current camera
  • The ability to specify a video size to record in

Example: On a LG G6 set at 16:9 be able to record in 1900x1080 or 1280x720

Crash when exiting the camera and coming back

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
    }

Preview expanding out of CameraView bounds for non standard view size

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:

  1. Define CameraView with width = 720 and height = 540
  2. The aspect ratio is still 4:3
  3. Start the camera cameraView.start()
  4. Check Layout Inspector

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

  • with ProGuard
  • without ProGuard

Device:

  • Device: Samsung Galaxy 8
  • OS: Android Oreo (8.0)
  • API: 26
  • Lib version v4.8.1

Branch Name (if using as a local module)

  • master
  • development

error: expected enum but got (raw string) single_capture.

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

App does extra flash when getting out of camera

Steps to reproduce the behavior:

  1. Open Sample App
  2. Turn on the flash if its not enable
  3. Take the picture. Make sure that the flash is happening
  4. Get out of the camera by back button

Actual behavior
You will see that an extra flash occurs

Expected behavior
When pressed back, it should not flash

  • Devices
    Nexus 6P Android 8.1.0 (Huawei angler (Android 8.1.0)
    Nexus Android 6.0

AAPT linking references error

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>

Failed to record video with 9:16 aspect ratio

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

Camera.isVideoRecording always returns false

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.

Not starting on some devices

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"

Camera 1 crash

@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):

  • Device: samsung ,xiaomi, lg, sony, others
  • OS: 4(98%), 6(2%)
  • API: 19,20,23
  • App version 2.1.6

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)

in android 6.0 not working

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)

Stretched preview after camera switch within an activity with android:screenOrientation="portrait"

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

  1. Start Activity with android:screenOrientation="portrait" including CameraView (hold the device in portrait orientation)
  2. Rotate device to landscape
  3. Switch Camera

Expected behavior
A non streched camera preview aber switching the camera

Using ProGuard

  • with ProGuard
  • without ProGuard

Screenshots
Device in portrait mode works very good!
Screenshot_20190813-123147

Device rotated to landscape and camera switch twice (to front and again to back camera)
Screenshot_20190813-123233

I'm using the Version 3.4.3

More than one file was found with OS independent path 'META-INF/atomicfu.kotlin_module'

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

  • without ProGuard

Device (please complete the following information):

  • Device: NA
  • OS: NA
  • API: 29
  • App version 3.5.5-alpha
    minSdkVersion 21
    targetSdkVersion 29
    compileSdkVersion 29
    gradle 3.5.3
    using Java 7

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'
}

Support for fixed orientation view and landscape video/image

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.

hi?

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.

About video recording

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.