录制一分钟的音频
我正在 Android 中进行音频录制。
我想录制最多 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;
}
但是在停止重新编码按钮时,我需要写什么?
I am working with audio recording in Android.
I want to record audio maximum of 1 minute and if user ask to stop before one minute it should be stop.
I have record audio code and it works perfectly.
How can I set time duration it?
If solution is thread.sleep
then it's ok. I do something like same:
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;
}
but at stop recoding button, what do I need to write?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用此解决方案:
持续时间以毫秒为单位,因此您必须使用:
You can use this solution:
The duation is in ms, so you have to use: