我正在用MediaRecorder应用程序,我想显示录制音频的时间限制。MediaRecorder仅用于录制声音。任何人都知道在做媒体录制时如何显示时间。

最佳答案

如果您已经为录制和停止编写了MediaRecorder的音频奠定了基础,那么获取录制的持续时间并不太困难。
显示持续时间只是在记录开始时设置为start_time
然后通过使用System.currentTimeMillis();我们可以执行循环,直到记录停止。

final Handler handler = new Handler();
Runnable update_runnable = new Runnable() {
    public void run() {
        updateTextView();
    }
};

然后使用Runnable您可以这样做:
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

08-04 05:02