2011-09-09 213 views
-1

我开发的音频记录的应用程序。我只想录制30秒的音频。需要帮助的录音

如何设置的持续时间录制音频和自动播放键进入,而音频剪辑播放端停止按钮?我如何在我的应用程序中实现这一点?

+0

http://rehearsalassist.svn.sourceforge.net/viewvc/rehearsalassist/android/trunk/src/urbanstew/RehearsalAssistant/RehearsalAudioRecorder.java?view=markup –

回答

1

可以使用MediaRecorder

的setMaxDuration(INT max_duration_ms)它设置记录会话的最长持续时间(毫秒)。在setOutFormat()之后但在prepare()之前调用此方法。记录达到指定的时间后,通知将被发送到MediaRecorder.OnInfoListener和记录将被停止。

MediaRecorder recorder = new MediaRecorder(); 
recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
recorder.setOutputFile(PATH_NAME); 
recorder.setMaxDuration (DURATION) 
recorder.prepare(); 
recorder.start(); 
+0

@Thanks您的回复,我用这个代码,但我从这一行recorder.setMaxDuration(30) – John

+0

函数接受时间以毫秒为单位得到了异常。因此,尝试使用: recorder.setMaxDuration(30000); //30秒 – Permita

+0

@sorry为我的错误,现在的工作很好,谢谢! – John