RAAAAM
RAAAAM

Reputation: 3380

How to set time calculation in MediaRecorder

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 MediaRecorder.

Upvotes: 3

Views: 4663

Answers (1)

John Giotta
John Giotta

Reputation: 16974

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

Upvotes: 4

Related Questions