1. Download the #1 Android News App:   EarlyBird - News for Android
    Dismiss Notice

How to use MediaPlayer mp.stop(); help

Last Updated:

  1. JohnsenAndreas

    JohnsenAndreas New Member

    Hello forum!

    I have spent hours trying to make a button that can play sound and if i click it again the sound will stop. I have only managed to get the sound playing. If i use mp.stop(); the sound will not start at all...

    my source code is:

    package AndreasJohnsen.buttonstartstop;

    import android.app.Activity;
    import android.media.MediaPlayer;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;

    public class buttonstartstopActivity extends Activity {

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

    final MediaPlayer mpButtonOn = MediaPlayer.create(this, R.raw.cuttersound);


    Button ButtonOn = (Button) findViewById(R.id.button1);

    ButtonOn.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
    // TODO Auto-generated method stub




    reegards Andreas Johnsen :eek:


Share This Page