还是先看代码,用一种最笨的方式实现了录音的功能:
try { String path = "/sdcard/recorder.amr"; MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path+name); recorder.prepare(); recorder.start(); try { Runnable.wait(10000); } catch (Exception exp) { exp.printStackTrace(); } recorder.stop(); recorder.release(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
10秒钟哦,等也得等,不等也得等,不用线程怎么行。
录像就是Audio+Video,所以还要加点东西,看代码:
path = "/sdcard/v.3gp";
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoSize(176, 144);
recorder.setVideoFrameRate(15);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
理论上是没错的,可我用模拟器测试录制视频还是会报错