我的代码:
public int onStartCommand(Intent intent, int flags, int startId) {
mediaRecorder = new MediaRecorder();
mediaRecorder.reset();
String phoneNum = intent.getStringExtra("number");
String path = new Helper().getPath();
String time= new Helper().getTimeHelper();
String recFullPath = path+"/"+phoneNum+"_"+time+".mp4";
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mediaRecorder.setOutputFile(recFullPath);
try{
mediaRecorder.prepare();
}catch (Exception e)
{
e.printStackTrace();
}
mediaRecorder.start();
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
mediaRecorder.stop();
mediaRecorder.reset();
mediaRecorder.release();
mediaRecorder=null;
}
}
谢谢Rotem。