title: Android Mediaplayer Play/Stop help needed
body: <p>I am trying to create my first android application and what I'm trying to accomplish here is to play a sound and then stop it via the same button.  </p>
  
  <p>It kind of works as it plays the sound when I click it and stops when I click it again but will not play when I click it the third time to start the sound again.</p>
  
  <p>I'm eventually going to have a few sounds in here and so would like to know if how my project is laid out correctly? Can I save some time anywhere? Have I got something the wrong way round?</p>
  
  <pre><code>package test.soundy.com;
  
  import android.app.Activity;
  import android.media.MediaPlayer;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  
  public class TestActivity extends Activity {
  private MediaPlayer sound;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      sound = MediaPlayer.create(Test.this, R.raw.sound1);  
  
      Button test = (Button)this.findViewById(R.id.button1);
      test.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
              if (sound.isPlaying()) {
                  sound.stop();
              } else {
                  sound.start();
              }
          }
      });
  
  
  }
  }
  </code></pre>
  
  <p>Any help would be much appreciated, thanks.</p>