我正在用 MediaRecorder 做应用,我想显示录制音频的时间限制。 MediaRecorder 仅用于录制语音。任何人都知道如何在执行 MediaRecorder 时显示时间。
最佳答案
如果您已经为使用编写的 MediaRecorder 录制和停止音频奠定了基础,那么获取录制的持续时间并不太困难。
显示持续时间只是 start_time
在记录开始时设置为 System.currentTimeMillis();
。
然后通过使用 Runnable
我们可以执行循环直到记录停止。
final Handler handler = new Handler();
Runnable update_runnable = new Runnable() {
public void run() {
updateTextView();
}
};
然后使用 updateTextView()
你会做这样的事情:
long duration = (int) ((System.currentTimeMillis() - start_time) / 1000);
// ... set TextView with duration value
handler.postDelayed(update_runnable, 1000); // handler re-executes the Runnable
// every second; which calls
// updateTextView
关于android - 如何在MediaRecorder中设置时间计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7308070/