Pause Preview and Restart

1,933 views
Skip to first unread message

Rajesh P

unread,
Sep 23, 2020, 9:03:58 AM9/23/20
to Android CameraX Discussion Group
Can anyone guide me is there anyway to pause and restart the preview ?

As of now, I'm unbinding all use cases and binding it once again. Is there any other way to do it ?

Vinit Modi

unread,
Sep 23, 2020, 11:09:19 AM9/23/20
to Rajesh P, Android CameraX Discussion Group
Would your app be in the foreground when you want to pause and restart the preview? 

Vinit 

On Wed, Sep 23, 2020, 6:04 AM Rajesh P <raj...@versionx.in> wrote:
Can anyone guide me is there anyway to pause and restart the preview ?

As of now, I'm unbinding all use cases and binding it once again. Is there any other way to do it ?

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/6786bbdf-1f1b-464c-ba65-109b8c4adc89n%40android.com.

Rajesh P

unread,
Sep 24, 2020, 2:39:03 AM9/24/20
to Android CameraX Discussion Group, Vinit Modi, Android CameraX Discussion Group, Rajesh P
Yeah the screen will always be on for preview. 

Leo Huang

unread,
Sep 24, 2020, 6:45:15 AM9/24/20
to Android CameraX Discussion Group, Rajesh P, Vinit Modi, Android CameraX Discussion Group
One way is to set Preview.setSurfaceProvider with null SurfaceProvider, the document indicates that

"If the provider is removed by calling this again with a null SurfaceProvider then the camera will stop producing data for this Preview instance."

For bind/unbind way, it can only unbind Preview and then rebind it. The performance should be bit better than unbind all use cases because the camera device will remain open if there are still bound use cases.
Rajesh P 在 2020年9月24日 星期四下午2:39:03 [UTC+8] 的信中寫道:

Rajesh P

unread,
Oct 7, 2020, 12:27:35 PM10/7/20
to Android CameraX Discussion Group, leoh...@google.com, Rajesh P, Vinit Modi, Android CameraX Discussion Group
No it's not working. It's still producing the previews.

Leo Huang

unread,
Oct 8, 2020, 2:24:58 AM10/8/20
to Rajesh P, Android CameraX Discussion Group, Vinit Modi
Do you mean "Preview.setSurfaceProvider with null SurfaceProvider" is not working?

I gave a try on current latest CameraXBasic (CameraX 1.0.0-beta10 and view 1.0.0-alpha17)

and modify the ImageButton onClick behavior as

        controls.findViewById<ImageButton>(R.id.camera_capture_button).setOnClickListener {
            if (hasSetSurfaceProvider) {
                preview?.setSurfaceProvider(null)
            } else {
                preview?.setSurfaceProvider(viewFinder.surfaceProvider)
            }
            hasSetSurfaceProvider = !hasSetSurfaceProvider
        }

and it seems to work.

Could there be other reason to cause it fail? Maybe some code snippet can help to figure it out.

Rajesh P <raj...@versionx.in> 於 2020年10月8日 週四 上午12:27寫道:

Rajesh P

unread,
Oct 8, 2020, 2:46:02 AM10/8/20
to Android CameraX Discussion Group, leoh...@google.com, Android CameraX Discussion Group, Vinit Modi, Rajesh P
I'm not usig for image catpure. I'm using it for face detection using image analyser. May be this could be the reason ?

I feel like in some phones it's working and some phones it's not. 

I'll try with image capture anyways to check this feature.

Reply all
Reply to author
Forward
0 new messages