title: How do I play a sound on an ImageButton click in another Activity?
body: <p>I am trying to create a method of an image button. When it's clicked, the background music stops and the image button change to another image. When pressed again, it will return as if it was at the first time and replay the music.</p>
  
  <p>I am trying a Boolean. When it's true, the music start and when it's false the music, but it doesn't work!</p>
  
  <p>In addition, how I can make another activity play or stop the music depending on the main activity?</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      MediaPlayer mp;
      ImageButton SoundButton;
      ImageButton NoSoundButton;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          SoundButton = new ImageButton(this);
          NoSoundButton = new ImageButton(this);
          /*---------Image Buttons--------*/
  
          SoundButton=(ImageButton) findViewById(R.id.sound);
          SoundButton.setVisibility(View.GONE);
          NoSoundButton=(ImageButton) findViewById(R.id.nosound);
          NoSoundButton.setVisibility(View.VISIBLE);
  
          /*---------Media Player--------*/
  
          mp = new MediaPlayer();
          mp = MediaPlayer.create(this, R.raw.aud);
          mp.setLooping(true);
          mp.start();
      }
  
      public void nosound(View view) {
          SoundButton.setVisibility(View.VISIBLE);
          NoSoundButton.setVisibility(View.INVISIBLE);
          mp.stop();
          mp.prepareAsync();
      }
  
      public void sound(View view) {
          SoundButton.setVisibility(View.INVISIBLE);
          NoSoundButton.setVisibility(View.VISIBLE);
          mp.start();
      }
  }
  </code></pre>