1
   OnClickListener startRecord = new OnClickListener() {
      public void onClick(View v) {

      String audiodir = new String(Environment.getExternalStorageDirectory() + File.separator +   "Test" + File.separator);

         while (stop_rec == false){

                SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
                Date now = new Date();
                String fileName = formatter.format(now) + ".raw";

                String audiopath = new String(audiodir + fileName);

                MediaRecorder recorder = new MediaRecorder();
                recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
                recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);

                recorder.setOutputFile(audiopath);
                try {
                  recorder.prepare();
                } catch (Exception e){
                    e.printStackTrace();
                }


                 recorder.start();   // Recording is now started

                 new RecordActivity().execute(); //waiting

                 recorder.stop();
                 recorder.reset();   
                 recorder.release(); 
            }
            stop_rec = false;
        }
    };

    //@Override
    OnClickListener stopRecord = new OnClickListener() {
        public void onClick(View v) {
            stop_rec = true; //for stop recording
        }
    };`

嗨,我的问题在 recorder.setAudioSource(MediaRecorder.AudioSource.MIC) 的行上,它会生成一些 RuntimeException。

更多细节我看不到,因为还有另一个错误:“类文件编辑器,找不到源:源附件不包含文件 InvocationTargetException.class 的源......”

有谁能够帮我?

4

2 回答 2

0

有没有加

<uses-permission android:name="android.permission.RECORD_AUDIO"/>

在清单中?

于 2013-02-25T16:32:50.230 回答
0

不要忘记设置录制音频的权限

<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>

于 2013-02-25T16:32:57.823 回答