title: Play and stop music when press and release a button
body: <p>I'm coding a music app with buttons. I want to make music sound while a button is pressed but stop it when it's released. Also I want to play the music in a constant loop without separation between loop times. 
  Now when I press the button music starts to play but when I release the button it stills playing untill the end of the file.</p>
  
  <p>This is the code:</p>
  
  <pre><code>    @Override
          public boolean onTouch(View v, MotionEvent event) {
              MediaPlayer do2n = MediaPlayer.create(this, R.raw.do_leg);
              if(event.getAction() == MotionEvent.ACTION_DOWN) {
                  if(v.getId()==R.id.dor){
                     do2n.start();
                  }
              } else if (event.getAction() == MotionEvent.ACTION_UP) {
                  if(v.getId()==R.id.dor){
                      if (do2n != null)
                          do2n.release();
                  }
              }
          return true;
  }
  </code></pre>