媒体录像机不起作用

时间:2013-02-25 16:27:50

标签: android

   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的源....”

有人能帮助我吗?

2 个答案:

答案 0 :(得分:0)

你有没有添加

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
清单中的

答案 1 :(得分:0)

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

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