只要用户按下ImageView
,我就需要播放某个声音,并在用户停止按住时暂停它。在使用MediaPlayer
做任何事情之前,我尝试用Vibrator
(请不要嘲笑这一点)对象来测试它。我已经实现并设置了OnTouchListener
:
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
vib.vibrate(50);
break;
case MotionEvent.ACTION_MOVE:
/*--- no action required ---*/
break;
case MotionEvent.ACTION_UP:
vib.cancel();
break;
}
return false;
}
但是,无论我按住ImageView
多长时间,振动动作都只执行一次。我想MediaPlayer
会以同样的方式做出反应。我做错了什么?
P.S。正确检测到印刷机,因为Vibrator
仅在我松开手指后才记录“取消()”。
答案 0 :(得分:1)
因为功能
而停止vib.vibrate(50);
你在振动check
中设置为50毫秒时间void vibrate(long milliseconds)
Vibrate constantly for the specified period of time.
我认为你的其他代码是正确的。