2011-05-14 53 views
1

嗨Ia的机器人录音1分钟

与录音工作我想记录1分钟音频最大,如果用户要求一分钟之前就停止,应停止

我有记录音频代码和它完美的作品。

我该如何设置持续时间呢?

如果解决方案的Thread.Sleep那么它的确定 我所以像同

if (start) { 
     startRecording(); 
     try { 
       Thread.sleep(60000); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 
    } else { 
    //What should do ? to stop thread this Thread.sleep(60000); 

    callToStopRecording(); 
    } 

    private void startRecording() { 
     mRecorder = new MediaRecorder(); 
     mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
     mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
     mRecorder.setOutputFile(path + mFileName); 
     mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 

     try { 
      mRecorder.prepare(); 
     } catch (IOException e) { 
      Log.e("Camera Error", "prepare() failed"); 
     } 
     mRecorder.start(); 
    } 

    private void stopRecording() { 
     mRecorder.stop(); 
     mRecorder.release(); 
     mRecorder = null; 
    } 

,但在停止录像按钮,我应该怎么需要写?

帮助我的迫切

+0

你能告诉我如何录制... – Dinash 2011-05-14 06:09:44

+0

我已经添加了代码检查出来 – Freni 2011-05-14 08:27:39

+0

在停止录制按钮中调用stopRecording方法 – Dinash 2011-05-14 08:37:45

回答

3

您可以使用此解决方案:

mRecorder.setMaxDuration(max_duration_ms); 

的duation是毫秒,所以你必须使用:

mRecorder.setMaxDuration(6000); 

如果这个解决方案的工作,谢谢检查正确的答案。