title: Need a sound to play every second if a button is toggled
body: <p>I have a toggle button and i need the 'mp' sound to play every second if that button is toggled.The code below is what i tried and it does play the sound every second but the button stops responding so i can't turn it off.</p>
  
  <pre><code>    ToggleButton btn = findViewById(R.id.button);
      final MediaPlayer mp  = MediaPlayer.create(this, R.raw.beat);
  
      btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
              while (isChecked) {
                  mp.start();
                  try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
          }
      });
  </code></pre>
  
  <p>Thank you in advance.</p>