【发布时间】:2015-07-14 23:49:10
【问题描述】:
我每次都尝试播放声音,点击一个按钮。声音已播放,但我每次都需要播放(就像您键入内容时播放的声音一样),问题是,我的并不总是播放。我认为这是因为单击按钮的延迟很小。
new MediaPlayer sound = new MediaPlayer().create(getApplicationContext(), R.raw.sound);
button.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (x >= pS.getX() && x < (pS.getX() + squareS.getWidth()) &&
y >= pS.getY() && y < (pS.getY() + squareS.getHeight())) {
pS.setRes(pSquareOffRes);
pS.setX(pS.getX() - squareS.getWidth());
pS.setY(pS.getY() - squareS.getHeight());
pS.setTouched(true);
pS.lock(true);
touchLimitA = System.currentTimeMillis();
timer = 3;
sound.start();
break;
}
return false;
}
我很高兴你能给我任何建议:)。
【问题讨论】:
标签: java android audio android-studio