Q:

Stopping media player

So I'm making sound application for android and I am stuck at 1 little problem.
When I click on button1, it plays sound. That part is working good, but I want my app to stop current media player upon clicking on button2, and play Button 2 sound.
  final MediaPlayer mp = MediaPlayer.create(this, R.raw.kalas);

  ImageButton sound1=(ImageButton) findViewById(R.id.sound1);
  sound1.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (mp.isPlaying()) {
            mp.pause();
            mp.seekTo(0);
        }
        else {

            mp.start();

        }

    }
});

A:

Create new ImageButton and set onClickListener to the button and check if it is playing and then stop the mediaPlayer by mp.stop();
final MediaPlayer mp = MediaPlayer.create(this, R.raw.kalas); 
ImageButton sound1=(ImageButton) findViewById(R.id.sound1); 
ImageButton sound2=(ImageButton) findViewById(R.id.sound2); 

sound1.setOnClickListener(new View.OnClickListener() { 
    @Override public void onClick(View v) { 
        // TODO Auto-generated method stub 
        if (mp.isPlaying()) { 
            mp.pause(); 
            mp.seekTo(0); 
        } 
        else { 
            mp.start(); 
        } 
    } 
}); 

sound2.setOnClickListener(new View.OnClickListener() { 
    @Override public void onClick(View v) { 
        // TODO Auto-generated method stub 
        if (mp.isPlaying()) { 
            mp.stop
        } 

    } 
}); 

