title: Stop MediaPlayer
body: <p>I made an android application where you can click buttons to play sounds. Every time, you click the button, a new MediaPlayer is getting created and the problem is, when you push a button during another sound is still playing, they are playing at the same time, but I want, that the previous sounds stops when you push a button. I already tried this code but my application crashes every time I press the button:</p>
  
  <pre><code>MediaPlayer mp;
  Button button;
  
  button = (Button) findViewById(R.id.button);
  
  button.setOnClickListener(new OnClickListener() {
  
  
          @Override
          public void onClick(View v) {
  
              if(mp.isPlaying()){
  
                  mp.stop();
  
              }
  
              mp = MediaPlayer.create(getApplicationContext(), R.raw.sound);
              mp.start();
  
          }});
  </code></pre>
  
  <p>Is there a way to solve my problem?</p>