Download the New LearnVern Android App and enter Lucky Draw to win Free Certificate
Surface View and Media Recorder
In today's video our topic is Surface View and Media Recorder.
Surface view represents preview of live camera. It is used when we want any live surface preview in our application in order to take image or video.
Here is one example of SurfaceView,
public class CameraView extends SurfaceView implements SurfaceHolder.Callback
private SurfaceHolder mHolder;
private Camera mCamera;
public CameraView(Context context,Camera camera)
Now suppose in some case, we need to capture the image in landscape mode or change the mode of orientation. So before changing the application orientation, you need to stop the preview, rotate and then start it again.
Important part of code for that is :
Log.d("ERROR","Camera error on surfaceChanged"+e.getMessage());
public void surfaceDestroyed(SurfaceHolder surfaceHolder)
Now we use Media Recorder when we want to capture video in android application. There are several methods of camera application which we need to use carefully while media recording, they are, Camera lock, Camera unlock, Camera open, Camera.release.
We need to follow the below mentioned specific order for MediaRecorder,
Unlock camera with Camera.unlock()
Start recording using MediaRecorder.start()
Record the video
Stop recording using MediaRecorder.stop()
Release media recorder with MediaRecorder.release()
Lock camera using Camera.lock()
Have a friend to whom you would want to share this course?