• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How do I record audio for X seconds?

PnzrDrgoon

Lurker
Jun 11, 2010
6
0
Google has an example on how to record audio here:
Audio and Video | Android Developers


The problem with their example is they don't explain what to do to keep recording for a set time period. I've tried putting the thread to sleep for 10 seconds with Thread.sleep(10000); but that seems to make the recording stop.

Any help would be appreciated.

PHP:
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setOutputFile(path);
    
    SLEEP HERE?  BUSY WAITING?  WHAT DO I DO HERE FOR 10 SECONDS?

    recorder.prepare();
    recorder.start();

Edit:
Okay, so after some digging around I've tried to use
PHP:
recorder.setMaxDuration(10000);//set max time length of recording
recorder.setOnInfoListener(new OnInfoListener()
{
     public void onInfo(MediaRecorder mr, int what, int extra) {

					mr.stop();
					mr.release();
				}
}

But after my 10 seconds are up the OnInfoListener event is never being fired. What am I doing wrong?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones