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 explanation for this one my code is
public class Simple extends Activity {
/** Called when the activity is first created. */
Button button,button2;
MediaRecorder recorder;
Camera camera;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button=(Button) findViewById(R.id.button1);
button2=(Button) findViewById(R.id.button2);
camera=Camera.open();
Camera.Parameters params = camera.getParameters();
camera.setParameters(params);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Video Start", Toast.LENGTH_LONG).show();
String mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/temp.3mp4";
recorder=new MediaRecorder();
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoFrameRate(10);
recorder.setVideoSize(200, 300);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setMaxDuration(50000);
recorder.setMaxFileSize(5000000);
recorder.setOutputFile(mFileName);
try {
recorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(getBaseContext(),e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(getBaseContext(),e.toString(), Toast.LENGTH_LONG).show();
}
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Video Stop", Toast.LENGTH_LONG).show();
recorder.stop();
}
});
}
}
Here is the code for recording video...
and here is the Preview Class....