title: Android: Pause voice Recorder and Resume
body: <p>I've used following code as base to create a recorder. I can start and stop audio recording and it gets saved properly in the location. But now I have a requirments to pause the voice recorder </p>
  
  <p>How to pause the audio recorder? And resume voice recording? I've seen a voice recording appliation in my samsung galaxy Ace, it has a pause button.</p>
  
  <p>Can someone enlighten me.</p>
  
  <pre><code>public class audio {
       final MediaRecorder recorder = new MediaRecorder();
        final String path;
  
        /**
         * Creates a new audio recording at the given path (relative to root of SD card).
         */
        public audio(String path) {
  
          this.path = sanitizePath(path);
        }
  
        private String sanitizePath(String path) {
          if (!path.startsWith("/")) {
            path = "/" + path;
          }
          if (!path.contains(".")) {
            path += ".3gpp";
          }
          return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
        }
  
        /**
         * Starts a new recording.
         */
        public void start() throws IOException {
          String state = android.os.Environment.getExternalStorageState();
          if(!state.equals(android.os.Environment.MEDIA_MOUNTED))  {
              throw new IOException("SD Card is not mounted.  It is " + state + ".");
          }
  
          // make sure the directory we plan to store the recording in exists
          File directory = new File(path).getParentFile();
          if (!directory.exists() &amp;&amp; !directory.mkdirs()) {
            throw new IOException("Path to file could not be created.");
          }
  
         try {
             recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
              recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
              recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
              recorder.setOutputFile(path);
  
              recorder.prepare();
              recorder.start();
      } catch (Exception e) {
          e.printStackTrace();
          // TODO: handle exception
      }
        }
  
        /**
         * Stops a recording that has been previously started.
         */
        public void stop() throws IOException {
          recorder.stop();
          recorder.reset();
          recorder.release(); 
        }
  
        public void pause() {
  
        }
  
      }
  </code></pre>