Hi,
I am trying to solve the problem with initializing video preview and releasing resources when the application exits.
in onResume() the following methods are executed:
holder.addCallback(surfaceCallback);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
and in onPause() the following method is called:
holder.removeCallback(surfaceCallback);
where
surfaceHolder is defined the following way:
SurfaceHolder.Callback surfaceCallback = new SurfaceHolder.Callback() {
public void surfaceCreated(SurfaceHolder holder) {
Log.w("CapturePreview", "Surface Created!");
initializeVideo(mCaptureMode);
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.w("CameraView", " surface changed!");
if (mPausing) {
return;
}
initializeVideo(mCaptureMode);
}
public void surfaceDestroyed(SurfaceHolder holder) {
Log.w("CameraView", " surface destroyed!");
try {
recorder.stop();
} catch (IllegalStateException e) {
Log.w("CameraView", e.getMessage());
}
recorder.reset();
recorder.release();
Log.w("CameraView", " file size: " + sdFile.length());
}
};
The described logic successfully initializes the video preview but the problem is if I close the application (press the home button) and try to run the original camera application. In this case the camera application displays an error and closes. Also if I try to run the developing application after a while the video preview doesn't start.
Does anyone know how to fix the described problem?
Thanks!