开发者

How to set time calculation in MediaRecorder

开发者 https://www.devze.com 2023-04-02 19:17 出处:网络
I am doing application with MediaRecorder, i want to display the time limit of recording the audio. MediaRecorder is only used to record the voice. anyone know how to display the time while doing 开发

I am doing application with MediaRecorder, i want to display the time limit of recording the audio. MediaRecorder is only used to record the voice. anyone know how to display the time while doing 开发者_Python百科MediaRecorder.


If you have the ground work laid for the recording and stopping of audio with MediaRecorder written, obtaining duration of recording isn't too difficult.

Displaying duration is simply start_time being set to System.currentTimeMillis(); at start of record.

Then by using a Runnable we can perform a loop until stop of record.

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

Then with the updateTextView() you'd do something like this:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消