title: How can I implement the "pause" function in my MediaPalyer?
body: <p>The "stop" and "play" work fine, but "pause" works like "stop". When I press pause, the audiofile stops playing and when I press play, it starts from the beginning. </p>
  
  <p>The "stop" and "play" work fine, but "pause" works like "stop". When I press pause, the audiofile stops playing and when I press play, it starts from the beginning. </p>
  
  <pre><code>import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  
  public class HelloMoonFragment extends Fragment 
  {
      private AudioPlayer mPlayer = new AudioPlayer();
      private Button mPlayButton;
      private Button mStopButton;
      private Button mPauseButton;
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup parent,
      Bundle savedInstanceState) 
      {
          View v = inflater.inflate(R.layout.fragment_hello_moon, parent, false);
          mPlayButton = (Button)v.findViewById(R.id.hellomoon_playButton);
          mPlayButton.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) 
              {
                  mPlayer.play(getActivity());
              }
              });
          mPauseButton = (Button) v.findViewById(R.id.hellomoon_pauseButton);
          mPauseButton.setOnClickListener(new View.OnClickListener() 
          {
              public void onClick(View v) 
              {
                   mPlayer.pause();
              }
              });
          mStopButton = (Button)v.findViewById(R.id.hellomoon_stopButton);
          mStopButton.setOnClickListener(new View.OnClickListener() 
          {
              public void onClick(View v) 
              {
                  mPlayer.stop();
              }
              });
          return v;
      }
      @Override
      public void onDestroy() 
      {
          super.onDestroy();
          mPlayer.stop();
      }
  
  }
  
  package com.example.hellomoon;
  
  import android.content.Context;
  import android.media.MediaPlayer;
  
  public class AudioPlayer {
  
      private MediaPlayer mPlayer;
      public void stop()
      {
          if(mPlayer != null)
          {
              mPlayer.release();
              mPlayer = null;
          }
  
      }
      public void pause()
      {   
  
          if(mPlayer.isPlaying()) 
              {
                  mPlayer.pause();
  
              }
      }
      public void play(Context c)
      {
  
  
          stop();
          mPlayer = MediaPlayer.create(c, R.raw.one_small_step);
  
          mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() 
          {
  
              @Override
              public void onCompletion(MediaPlayer mp) 
              {
                  stop();
              }
  
          });
          mPlayer.start();
      }
  }
  </code></pre>