title: mediaRecorder java.langRuntimeException stop failed - recording audio
body: <p>I'm trying to record audio, and it needs to be high quality.</p>
  
  <p>This code is working fine on a lot of devices, however on some devices like the galaxy s4 mini, moto G, and even the Galaxy s4 and HTC one mini, it will not work.</p>
  
  <p>Here is my recording method</p>
  
  <pre><code>public class RecordingHandler {
  
      private static MediaRecorder recorder;
  
      static void beginRecording(String output) throws Exception {
  
          ditchMediaRecorder();
          File outFile = new File(output);
          if (outFile.exists())
              outFile.delete();
          recorder = new MediaRecorder();
          recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
          recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
          recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
          recorder.setAudioEncoder(MediaRecorder.getAudioSourceMax());
          recorder.setAudioEncodingBitRate(16);
          recorder.setAudioSamplingRate(44100);
          recorder.setOutputFile(output);
          recorder.prepare();
          recorder.start();
      }
  
      static void ditchMediaRecorder() {
          // if we have the recorder, release it
          if (recorder != null)
              recorder.release();
      }
  
      static void stopRecording() {
          if (recorder != null) {
  
              try {
                  recorder.stop();
              } catch (RuntimeException stopException) {
                  // handle cleanup here
                  Log.d("Recording Handler", "Runtime Exception");
              }
          }
      }
  
  }
  </code></pre>
  
  <p>The error I'm getting</p>
  
  <pre><code>java.lang.RuntimeException: stop failed.
  at android.media.MediaRecorder.stop(Native Method)
  at com.appulse.beatbox.RecordingHandler.stopRecording(RecordingHandler.java:34)
  at com.appulse.beatbox.SoundRecord$5.onTouch(SoundRecord.java:347)
  at android.view.View.dispatchTouchEvent(View.java:7784)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2169)
  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1613)
  at android.app.Activity.dispatchTouchEvent(Activity.java:2539)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2117)
  at android.view.View.dispatchPointerEvent(View.java:8005)
  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4300)
  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4179)
  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3714)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3764)
  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3733)
  at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3844)
  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3741)
  at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3901)
  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3714)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3764)
  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3733)
  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3741)
  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3714)
  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5973)
  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5946)
  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5909)
  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6057)
  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:214)
  at android.os.MessageQueue.nativePollOnce(Native Method)
  at android.os.MessageQueue.next(MessageQueue.java:138)
  at android.os.Looper.loop(Looper.java:134)
  at android.app.ActivityThread.main(ActivityThread.java:5872)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>