<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
public class MediaCaptureActivity extends Activity {
private MediaRecorder recorder;@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.capture);
Button start = (Button)findViewById(R.id.startRecord);
Button stop = (Button)findViewById(R.id.stopRecord);
recorder = new MediaRecorder();
start.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// SurfaceView sv = (SurfaceView)findViewById(R.id.surfaceView);
// recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
// recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
// recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/myVideo/");
path.mkdirs();
System.out.println("==================" + path.getAbsolutePath());
// recorder.setVideoFrameRate(20);
// recorder.setVideoSize(100, 100);
// recorder.setPreviewDisplay(sv.getHolder().getSurface());
try {
File file = File.createTempFile("myAudio", ".amr", path);
recorder.setOutputFile(file.getAbsolutePath());
recorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
recorder.start();
}
});
stop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
recorder.stop();
}
});
}
}