开发者

Track audio recording in android

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

    recorder.setMaxDuration(300000); 
    recorder.setAudioEncoder(MediaRecorder.Audio开发者_如何学CEncoder.AMR_NB); 
    recorder.setOutputFile(path); 
    recorder.prepare(); 
    recorder.start(); 

This is my code for recording an audio..

I need to track the time at each seconds to show the recorded time like 00:05 . I Have given a time limit of 5minutes.


Thanks Jim Blackler I got it :).

I tried 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));
}
};
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜