Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera.lock, unlock() managed automatically for you since Android 4.0?

I just started android development and wrote a simple camera app using this tutorial: http://developer.android.com/guide/topics/media/camera.html#custom-camera

there i read: "Note: Starting with Android 4.0 (API level 14), the Camera.lock() and Camera.unlock() calls are managed for you automatically."

but what does this mean? my camera app supports Android 16 (4.1.2) and 17 (4.2.2) but if i discard the lock and unlock calls i get error from mediarecorder (-19). so how to let handle android it? or what does this mean "managed automatically"?

like image 780
dermoritz Avatar asked Nov 13 '22 01:11

dermoritz


1 Answers

As android documentation states lock() is called automatically for you in MediaRecorder.start(). I think that you couldn't remove the unlock() call because when the start() method call the lock() method on your camera, which is locked by default, it find the camera locket and so it rise a RuntimeException.

Since API level 14, camera is automatically locked for applications in start(). Applications can use the camera (ex: zoom) after recording starts. There is no need to call this after recording starts or stops.

like image 114
Matteo Corti Avatar answered Nov 15 '22 12:11

Matteo Corti