2015-07-13 66 views
0

正在我的應用程序中實現音頻錄製功能。通過媒體錄音機類,我們可以選擇SetMaxDuration(milliSeconds),在Audio Recorder class i中找不到錄製音頻的限制時間。 請幫助我做到這一點。如何設置錄音限制通過使用錄音機類?

+0

要停止使用錄音機類的錄音,您可以使用睡眠時間爲1000毫秒的線程,並獲得具有某個最大限制的計數器,並且達到該限制時,您可以停止在線程中進行錄製。 –

回答

0

你可以試試這個:

handler=new Handler(); 
Runnable r=new Runnable() 
{ 
public void run() 
{ 
    recorder.stop(); 
    recorder.release(); 
    } 

}; 
handler.postDelayed(r, 60000); 
0

請嘗試設置的最大值下面的代碼。

recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); 
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
recorder.setOutputFile(outputFile.getAbsolutePath()); 

recorder.setMaxDuration(60000); 
recorder.prepare(); 
recorder.start(); 

希望它適合你。