title: playing a looping sound when button is pressed in android
body: <p>my problem is a simple one.  i want to play a looping sound only when a button is pressed.  the following are the switch statement and if else approaches i've tried. at best, i can play the sound but it won't pause when the button is no longer pressed.</p>
  
  <pre><code>    public boolean onTouch(View v, MotionEvent event) {
   MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.clash);
  
   if (v.getId() == R.id.clash &amp;&amp; event.getAction() == MotionEvent.ACTION_DOWN){
    mp.setLooping(true);
    mp.start();
  
   }else if (v.getId() == R.id.clash &amp;&amp; event.getAction() == MotionEvent.ACTION_UP)
   {mp.pause();
  
   }
  }
  
      public boolean onTouch(View v, MotionEvent event) {
      MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.clash);
  
       switch (event.getAction()){
  
       case MotionEvent.ACTION_DOWN:
        mp.setLooping(true);
        mp.start();
  
       case MotionEvent.ACTION_UP:
        mp.pause();
      }
  
  
      return false;
     }
  </code></pre>