I kneed to know when my tone generator has stopped playing.
I want to play the dtmf tone for 50 ms and then wait 50 to play the next tone. i wanted to use this code.
private void playtones() {
new Thread(new Runnable() {
public void run() {
for(int i=0 ; i<=19 ; i++){
dtmftone.startTone(savetone.get(i) , 50);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
).start();
}
The sleep starts before the tone has stopped playing. How can i check that the tone has stopped playing? Or is there at better way to do this?
Thx for the help.
You should use the method wait(long millis) of ToneGenerator instead of Thread.sleep().
Be careful, the method does not wait the sound to have stopped, thus you have to take the duration of the beep into account:
And I am not sure whether you want to wait 50ms between two beeps. If you don't, just delete the "+ WAITING_DURATION"