2011-05-14 61 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); 

如果這個解決方案的工作,謝謝檢查正確的答案。