I'm trying to incorporate some camera-related features in my app. I open the camera manually and get the preview stream with setPreviewCallback
and startPreview
. I do not use the surface for displaying preview, but I do set it to comply with the Camera API docs. This is how I open the camera:
public Camera openCamera(int id)
{
m_openedCamera = Camera.open(id);
m_surfaceHolder = new SurfaceView(MyApplication.instance().getApplicationContext()).getHolder();
Assert.assertNotNull(m_openedCamera);
m_openedCamera.setPreviewDisplay(m_surfaceHolder);
m_openedCameraFacing = facing;
if (m_openedCamera != null)
m_openedCamera.setPreviewCallback(this);
m_openedCamera.startPreview();
}
And this is how I release it, nothing fancy here:
public void releaseCamera()
{
if (m_openedCamera != null)
{
m_openedCamera.stopPreview();
m_openedCamera.release();
m_openedCamera = null;
}
}
It kinda works at first, but as I release the camera, I get an exception "Method called after release()". To clarify: I do not call any camera methods after the camera has been released. Double and triple-checked under debugger that I don't. I think there's a mix of synchronous and asynchronous calls here that causes the problem.
hacksworkarounds in _[this SO topic](http://stackoverflow.com/questions/2386025/android-camera-without-preview)_. – Alex Cohn Oct 09 '14 at 15:04