I am writing code for Video Recording function with Media recorder., But it throws Io Exception,Illegal State Exception i searched many times in google but no proper explan
Here is the code for recording video...
recorder = new MediaRecorder();
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
mPreview = new Preview(VideoRecorder.this,recorder);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(mPreview);
recorder.start();
and here is the Preview Class....
class Preview extends SurfaceView implements SurfaceHolder.Callback
{
SurfaceHolder mHolder;
MediaRecorder tempRecorder;
public Preview(Context context,MediaRecorder recorder) {
super(context);
tempRecorder=recorder;
mHolder=getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
// TODO Auto-generated constructor stub
}
public Surface getSurface()
{
return mHolder.getSurface();
}
public void surfaceCreated(SurfaceHolder holder){
tempRecorder.setOutputFile("/sdcard/recordvideooutput.3gpp");
tempRecorder.setPreviewDisplay(mHolder.getSurface());
try{
tempRecorder.prepare();
} catch (Exception e) {
String message = e.getMessage();
tempRecorder.release();
tempRecorder = null;
}
}
public void surfaceDestroyed(SurfaceHolder holder)
{
if(tempRecorder!=null)
{
tempRecorder.release();
tempRecorder = null;
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h)
{
}
}