3

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

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.

Can someone enlighten me.

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() && !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() {

      }

    }
Justin
  • 84,773
  • 49
  • 224
  • 367
Jay Mayu
  • 17,023
  • 32
  • 114
  • 148

1 Answers1

1

check out these 2 pages

http://developer.android.com/guide/topics/media/index.html http://developer.android.com/reference/android/media/MediaRecorder.html

according to the first article there is a pause()

but i dont see a pause() method on that second link so im not sure

the other thing that the first article references: "When you call stop(), however, notice that you cannot call start() again until you prepare the MediaPlayer again. Always keep the state diagram in mind when writing code that interacts with a MediaPlayer object, because calling its methods from the wrong state is a common cause of bugs."

so maybe u can just stop() prepare mediaplayer then start() again

owen gerig
  • 6,165
  • 6
  • 52
  • 91
  • as u said pause is available to MediaPlayer not the recorder. That's where I have this problem now :( – Jay Mayu Sep 01 '11 at 05:03
  • i hate to say anythings impossible but here is another stackoverflow post for the same thing - http://stackoverflow.com/questions/6128440/is-there-pause-available-in-mediarecorder-class – owen gerig Sep 01 '11 at 13:09
  • This is a real annoying feature missing in the native API :( – Jay Mayu Sep 01 '11 at 14:28
  • any chance of a vote up. i did answer the question :D either way sorry to hear this, hopefully in next release (oh what a common phrase for software) – owen gerig Sep 01 '11 at 14:41