让我们说当计时器在30秒时我需要播放声音,我该怎么做?谢谢! ♥ 这不起作用:
chronometer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
@Override
public void onChronometerTick(Chronometer chronometer) {
int c = 0;
c++;
if(c == 30) {
c = 0;
beep.start();
}
}
});
答案 0 :(得分:1)
计时器每秒不会打一次,你必须自己计算经过的时间。
chronometer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
int beeps = 1;
@Override
public void onChronometerTick(Chronometer chronometer) {
long myElapsedMillis = SystemClock.elapsedRealtime() - chronometer.getBase();
if(myElapsedMillis / 30000 >= beeps) {
beep.start();
beeps++;
}
}
});