实现录音的功能
//[1]获取MediaRecorder类的实例 recorder = new MediaRecorder();
/[2]设置音频的来源 recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
//[3]设置音频的输出格式 recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
//[4]设置音频的编码方式 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
//[5]保存的文件路径 recorder.setOutputFile("/mnt/sdcard/luyin.3gp");
//[5]准备录音
try { recorder.prepare();
} catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
记得加上相应的权限
1. <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
2. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
3. <uses-permission android:name="android.permission.RECORD_AUDIO" />
4. <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>