private void Record() {
// TODO Auto-generated method stub
Log.d("message","In Record function.................");
if(recorder==null)
{
recorder = new MediaRecorder();
try
{
//File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "saw.wav");
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setOutputFile(Environment.getExternalStorageDirectory().getCanonicalPath() + "saw.ogg" );
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
Log.d("message","Recording startedddd......");
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Log.d("message","Recording completed......");
}
catch (Exception e)
{
e.printStackTrace();
// TODO: handle exception
}
}
}
它提出了以下问题:
05-25 09:50:00.117: W/System.err(8323): java.io.IOException: No valid output file
05-25 09:50:00.117: W/System.err(8323): at android.media.MediaRecorder.prepare(MediaRecorder.java:603)
05-25 09:50:00.117: W/System.err(8323): at com.android.CallRecord.Listener.Record(Listener.java:73)
05-25 09:50:00.117: W/System.err(8323): at com.android.CallRecord.Listener.onCallStateChanged(Listener.java:35)
05-25 09:50:00.117: W/System.err(8323): at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:319)
05-25 09:50:00.117: W/System.err(8323): at android.os.Handler.dispatchMessage(Handler.java:99)
05-25 09:50:00.117: W/System.err(8323): at android.os.Looper.loop(Looper.java:130)
05-25 09:50:00.117: W/System.err(8323): at android.app.ActivityThread.main(ActivityThread.java:3687)
05-25 09:50:00.117: W/System.err(8323): at java.lang.reflect.Method.invokeNative(Native Method)
05-25 09:50:00.117: W/System.err(8323): at java.lang.reflect.Method.invoke(Method.java:507)
05-25 09:50:00.117: W/System.err(8323): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-25 09:50:00.117: W/System.err(8323): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-25 09:50:00.117: W/System.err(8323): at dalvik.system.NativeStart.main(Native Method)