Question

I was wondering whether it is possible to have 2 instances of the camera preview in android. What I mean is running 2 instances of the camera at the same time. If it is, how would one go about this, will there be need to implement an instance on a different thread? I have not used the camera API before, so I would appreciate it if I can have a heads up on the issue, so I don't waste time on it. Thank you.

Was it helpful?

Solution

It is not possible to have two open connections to the camera - you have to lock the camera in order to get a preview and it can only be locked once. Indeed, if you have the camera locked, and your app crashes before you've unlocked it, then nobody can use the camera!

See http://developer.android.com/reference/android/hardware/Camera.html#open%28int%29

You must call release() when you are done using the camera, otherwise it will remain locked and be unavailable to other applications.

...

RuntimeException: if connection to the camera service fails (for example, if the camera is in use by another process).

That said, you can certainly register a preview callback and take the preview data from your single camera instance to use in multiple views. But be aware of the issues with the YUV format of the raw byte[] data provided by the preview callback: Getting frames from Video Image in Android (note that the preview data is raw from the camera driver and may vary from device to device)

OTHER TIPS

Ignoring the big Why question, your best bet would be to make a service that interacts with the camera, and go from there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top