Code example for Camera

Methods: lockreleasestopPreview

0
	} 
 
 
	public void surfaceDestroyed(SurfaceHolder holder) {
		stopRecording(); 
		camera.stopPreview();
		previewRunning = false;
		camera.release();
	} 
	 
	public boolean startRecording(){ 
		try { 
			Log.d(TAG, "Unlock camera");
			camera.unlock();
 
			mediaRecorder = new MediaRecorder();
 
			mediaRecorder.setCamera(camera);
			mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
			mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
 
			mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
 
			path = Environment.getExternalStorageDirectory().getAbsolutePath()
						+ "/recordings/" + System.currentTimeMillis() + VIDEO_FILE + ".mp4";
			 
			mediaRecorder.setOutputFile(path);
 
			mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
 
            mediaRecorder.prepare();
            Log.d(TAG, "Prepared, start ...");
			mediaRecorder.start();
			 
			return true; 
		} catch (IllegalStateException e) {
			Log.e(TAG,e.getMessage());
			e.printStackTrace();
			return false; 
		} catch (IOException e) {
			Log.e(TAG,e.getMessage());
			e.printStackTrace();
			return false; 
		} 
	} 
	 
	public void stopRecording(){ 
		mediaRecorder.stop();
		Log.d(TAG, "Stopped recording");
		camera.lock();
	} 
	 
}