So I created a small app with a play and a stop button. When I press the play button it should loop until I press the stop button. The problem is, once I press the play button, I can't do anything else and the stop button is not responsive. If I try to press the stop button my app says app doesn't respond and quit. I don't know why this is happening and I'm super new to Android and Java so this is a bit complicated for me to know why it doesn't work. Here is my actual code :
Play and stop method :
public void play() {
playing = true;
while (playing) {
for (int i = 0; i < 4; i++) {
if (buttonArray[i].isChecked()) {
sp.play(snareId, 1, 1, 1, 0, 1);
}
if (!playing) {
break;
}
try {
Thread.sleep(1000);
if(i == 3) i = -1;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public void stop(){
playing = false;//
}
Main activity
playButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
mySample.play();
}
});
stopButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
mySample.stop();
}
});