I have a button (with a play icon as background) that starts reading some text (text to speech).
I want to change my button background (using a stop icon) while tts is speaking. Then, when it stop speaking i want to reset the button background to the first one (play icon).
I'm trying to do it using a thread but i'm not getting the wish result..
please take a look at my code on button click listener here:
if (tts.isSpeaking()) {
tts.stop();
btn4.setBackgroundResource(R.drawable.sound_icon);
} else {
Thread splashTread = new Thread() {
@Override
public void run() {
try {
while (tts.isSpeaking()) {
sleep(100);
btn4.setBackgroundResource(R.drawable.stop_icon);
}
} catch (Exception e) {
// do nothing
} finally {
btn4.setBackgroundResource(R.drawable.sound_icon);
}
}
};
if (myText.equals("")) {
speech("No text");
splashTread.start();
} else {
speech(myText);
splashTread.start();
}