How do I record audio for X seconds?


Last Updated:

  1. PnzrDrgoon

    PnzrDrgoon Member This Topic's Starter

    Joined:
    Jun 11, 2010
    Messages:
    6
    Likes Received:
    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:
    1.  
    2. recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    3.     recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    4.     recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    5.     recorder.setOutputFile(path);
    6.    
    7.     SLEEP HERE?  BUSY WAITING?  WHAT DO I DO HERE FOR 10 SECONDS?
    8.  
    9.     recorder.prepare();
    10.     recorder.start();
    11.  
    Edit:
    Okay, so after some digging around I've tried to use
    PHP:
    1.  
    2. recorder.setMaxDuration(10000);//set max time length of recording
    3. recorder.setOnInfoListener(new OnInfoListener()
    4. {
    5.      public void onInfo(MediaRecorder mr, int what, int extra) {
    6.  
    7.                     mr.stop();
    8.                     mr.release();
    9.                 }
    10. }
    11.  
    But after my 10 seconds are up the OnInfoListener event is never being fired. What am I doing wrong?
     

    Advertisement

Share This Page

Loading...