我还是Android开发人员的新手,我被卡住了。我有一个onTouchEvent为旋转图形提供动力并增加背景int [counter],触发一个短的声音效果(哔哔声)来播放。目前,如果[柜台]>在图10中,声音被播放(使用声音池)并且只要onTouchEvent保持计数器>就被概括地循环。 10.是否有可能在哔声效果的播放之间插入一个延迟,以便延迟越大,[计数器]的值越大?
实施例: if(counter == 10){delay = 80 //在MS中} if(counter == 90){delay = 10 // in MS}
我的代码:
sm = new SoundManager();
sm.initSounds(getBaseContext());
sm.addSound(1, R.raw.beep);
...
@Override
public boolean onTouchEvent(MotionEvent event) {
if (buttonClicked) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
counter++;
startRotating();
break;
case MotionEvent.ACTION_UP:
counter--;
stopRotating();
break;
}
}
return super.onTouchEvent(event);
}
public void startRotating() {
returnRotating = false;
if (!keepRotating) {
keepRotating = true;
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (keepRotating) {
degrees = (degrees + 10) % 360;
make(degrees);
counter = counter + 1;
if (counter > 10)
sm.playSound(1); // plays beep
handler.postDelayed(this, INTERVAL);
}
}
}, INTERVAL);
}
}
编辑:添加了代码
public void stopRotating() {
keepRotating = false;
if (!returnRotating) {
returnRotating = true;
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (returnRotating) {
degrees = (degrees - 10) % 360;
make(degrees);
counter = counter - 1;
if (counter > 10) {
sm.playSound(1); // plays beep
handler.postDelayed(this, INTERVAL);
}
}
}, INTERVAL);
}
}
答案 0 :(得分:0)
这样的事情怎么样?
if (counter > 10) {
sm.playSound(1); // plays beep
INTERVAL = 100 - counter;
handler.postDelayed(this, INTERVAL);