I have an application that calls a custom activity within it for the purpose of recording audio and video. It uses the MediaRecorder and the Camera classes. My issue is that when the user hits the back button or cancel while the video is recording, the activity always hangs on Camera.release(), but if the stop button is pressed first, there's no problem. Here's my code:
Stop button code:
mRecorder.stop(); // Stop recording
mRecorder.reset(); // Reset recorder
camera.stopPreview();
onDestroy():
mRecorder.reset(); // Release media recorder
mRecorder.release();
if (camera != null) {
camera.stopPreview();
camera.setPreviewCallback(null);
camera.release();
}
mRecorder = null;
camera = null;
I tried adding mRecorder.stop()
to onDestroy() as well but that didn't solve it. I checked here but none of the answers worked. I'm really stumped with this one.