我将发布一个问题代码。此代码在我的应用程序中运行良好
公共无效onStart(意图意图,int startId){
mSampleFile = null;
if (mSampleFile == null) {
String newFolder = "/Recording";
String extStorageDirectory = Environment
.getExternalStorageDirectory().toString();
File myNewFolder = new File(extStorageDirectory + newFolder);
if (!myNewFolder.exists()) {
myNewFolder.mkdir();
}
try {
if (myNewFolder != null) {
mSampleFile = File.createTempFile(SAMPLE_PREFIX,
SAMPLE_EXTENSION, myNewFolder);
}
} catch (IOException e) {
}
}
if (mSampleFile != null) {
SharedPreferences mysharedprefs8 = getSharedPreferences(mypref32,
MODE_MULTI_PROCESS);
String status = mysharedprefs8.getString("pass", "AMR_NB");
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
if (status.equalsIgnoreCase("AMR")) {
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
} else if (status.equalsIgnoreCase("MPEG")) {
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
} else if (status.equalsIgnoreCase("3GPP")) {
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
} else {
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
}
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.setOutputFile(mSampleFile.getAbsolutePath());
} catch (IllegalStateException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
mRecorder.setMaxDuration(600000);
try {
mRecorder.prepare();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
mRecorder.start();
mRecorder.setOnInfoListener(new OnInfoListener() {
@Override
public void onInfo(MediaRecorder mr, int what, int extra) {
// TODO Auto-generated method stub
try {
mRecorder.stop();
mRecorder.reset();
mRecorder.release();
} catch (Exception e) {
}
}
});
}