javaandroidcommonsware-cwaccwac-camera

Attach a different camera to host while it is running


In cwac-camera, I can override useFrontFacingCamera() to get either of the cameras on my device.

@Override public boolean useFrontFacingCamera() {
}

This is working fine, as long as I configure it before the host is built. But once the host is built and the preview is started, the event is not raised anymore and the camera therefore does not change.

What is the correct way to switch the camera while the preview is running?

I have tried to use restartPreview() which does not work because the preview is not actually stopped when restartPreview() is called. I cannot call stopPreview() because it is private. I saw there is a PreviewStrategy interface which might be there to cater for this functionality, but it's not documented and I don't understand how it's used. Sure I could tear everything down and set it up from scratch, but I guess that's not the way it should be done.

Can anybody shed light please.

PS: This is not a complaint about the documentation of the library. Not many other libraries are documented so thoroughly. It's just missing and/or I am to stupid to use it ;-(


Solution

  • What is the correct way to switch the camera while the preview is running?

    Switch to a separate CameraFragment, as the demo app does. There is no means to switch the camera once the fragment is created.