在Android中跟踪录音

时间:2011-05-13 08:42:16

标签: android

recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
    // 5 Minutes = 300000 Milliseconds

    recorder.setMaxDuration(300000); 
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
    recorder.setOutputFile(path); 
    recorder.prepare(); 
    recorder.start(); 

这是我录制音频的代码..

我需要跟踪每秒的时间,以显示记录的时间,如00:05。我给了5分钟的时间限制。

1 个答案:

答案 0 :(得分:1)

谢谢 Jim Blackler 我明白了:)。

我尝试了Updating the UI from a Timer

  private Handler mHandler = new Handler();

    ...

    OnClickListener mStartListener = new OnClickListener() {
    public void onClick(View v) {
    if (mStartTime == 0L) {
    mStartTime = System.currentTimeMillis();
    mHandler.removeCallbacks(mUpdateTimeTask);
    mHandler.postDelayed(mUpdateTimeTask, 100);
    }
    }
    };


private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
final long start = mStartTime;
long millis = SystemClock.uptimeMillis() - start;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;

if (seconds < 10) {
mTimeLabel.setText("" + minutes + ":0" + seconds);
} else {
mTimeLabel.setText("" + minutes + ":" + seconds); 
}

mHandler.postAtTime(this,
start + (((minutes * 60) + seconds + 1) * 1000));
}
};