CameraController example

551 views
Skip to first unread message
Assigned to husayn...@google.com by me

Peter Varga

unread,
Feb 3, 2021, 5:58:45 AM2/3/21
to Android CameraX Discussion Group
There is a great article on Medium about how to use the new CameraController.
The only problem is that there is no complete example so I can't see where to insert this into the initialization flow. 
I tried to search on internet but did not find any example at all. I write java code but in fact any language would be fine, could you please provide some example (complete with creating the use cases till the camera is ready) or give a link to one?

Thanks in advance,
Peter Varga

Message has been deleted

Husayn Abdul-hakeem

unread,
Feb 3, 2021, 11:31:55 AM2/3/21
to Peter Varga, Android CameraX Discussion Group
Hi Peter,

This Fragment (and its corresponding layout) is an example of how to use CameraController with the various features it supports, and it's in Java :)

--
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/2cfe0c22-16b9-4e95-b869-3f1cc3b3e876n%40android.com.

Peter Varga

unread,
Feb 3, 2021, 2:39:28 PM2/3/21
to Android CameraX Discussion Group, husayn...@google.com, Android CameraX Discussion Group, Peter Varga
Thank you very much, this is a great help! 

Peter

Peter Varga

unread,
Feb 21, 2021, 4:48:52 PM2/21/21
to Android CameraX Discussion Group, Peter Varga, husayn...@google.com, Android CameraX Discussion Group
Hi Husayn,

my code is already much nicer using CameraController so thanks for the example. I have some questions however.
- how can I check if the camera has flash? This used to be the hasFlashUnit() of camera class I thing, but I can't find any similar in cameracontroller, nor any way to reach the camera from it.1111
- is there any way to attach a listener to tap focus event? I would like to draw a circle on the focus point but could not find any way with CameraController.

Could you please help? 
Thanks in advance,
Peter

Husayn Abdul-hakeem

unread,
Feb 22, 2021, 2:35:58 PM2/22/21
to Android CameraX Discussion Group, varga.pet...@gmail.com, Husayn Abdul-hakeem, Android CameraX Discussion Group
Hi Peter,

I'm glad the CameraController sample helped you.

1. `CameraController` will include a new API `getCameraInfo()` in the next release, it should allow you to get information about the camera in use, including flash availability.
This means that after CameraX's initialization (`getInitializationFuture()`), you can call `controller.getCameraInfo().hasFlashUnit()`

2. You might be able to attach a touch listener to the controller's attached `PreviewView`, and handle touch tap events. Make sure to return false from the TouchListener so that CameraController also consumes the tap event and focuses on the tap region.
previewView.setOnTouchListener((v, event) -> {
    // Draw the focus ring if it's a tap event
    return false; // Allow other listeners to consume the event
})
Reply all
Reply to author
Forward
0 new messages