title: MediaRecorder, getMaxAmplitude always returns 0
body: <p>I have developed this small MediaRecorder application. I have 3 buttons- <code>Play</code> (for Start Recording), <code>Pause</code> (for stop recording), <code>Max</code> (for finding Max Amplitude). I Googled to get it correct, but nothing worked fine for me.</p>
  
  <p>The problem is it always give me 0 for <code>getMaxAmplitude</code>.</p>
  
  <p>Below is the code i am using. Can any one please help</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      Button play,pause, max;
  
      String outputFile = Environment.getExternalStorageDirectory().
            getAbsolutePath() + "/myexampl.3gp";
      MediaRecorder mrecorder=new MediaRecorder();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          play = (Button)findViewById(R.id.button1);
          pause= (Button)findViewById(R.id.button2);
          max = (Button)findViewById(R.id.button3);
  
          mrecorder = new MediaRecorder();
  
          mrecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
          mrecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
          mrecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
          mrecorder.setOutputFile(outputFile);
  
          play.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
  
                  try {
                      mrecorder.prepare();
                  } catch (IllegalStateException e) {
                      e.printStackTrace();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
  
                  mrecorder.start();
                  Toast.makeText(getApplicationContext(), "Starts Recording!", 
                      Toast.LENGTH_SHORT).show();
              }
          });
  
          pause.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
  
                  try {
                      mrecorder.stop();
                  } catch (IllegalStateException e) {
                      e.printStackTrace();
                  }
  
                  mrecorder.release();
                  Toast.makeText(getApplicationContext(), "Stops Recording!", 
                          Toast.LENGTH_SHORT).show();
              }
          });
  
          max.setOnClickListener(new OnClickListener() {
              int ampl=0;
  
              @Override
              public void onClick(View v) {
  
              try {
                  ampl=mrecorder.getMaxAmplitude();
              } catch (IllegalStateException e) {
                  e.printStackTrace();
              }
  
              Toast.makeText(getApplicationContext(), String.valueOf(ampl), 
                      Toast.LENGTH_SHORT).show();
          }
      });
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.activity_main, menu);
      return true;
  }
  </code></pre>
  
  <p>}</p>