我正在尝试在按下按钮时循环声音。
当我按下" MotionEvent.Action_Down"事件的按钮时,我该怎么办?我完成的方式只能运行一次。我尝试将返回语句更改为false,但它行不通。
seploop Mediaplayer选项对我无济于事,因为我想继续播放新的声音,尽管当前的声音未完成。
这是我的代码:
public boolean onClick(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
//here should not stop running the soundPool
soundPool.play(R.raw.sound1, 1, 1, 1, 0, 1);
}
if(event.getAction() == MotionEvent.ACTION_UP){
// stop running the soundpool
}
return true;
}
将第五个参数替换为-1:
soundPool.play(R.raw.sound1, 1, 1, 1, -1, 1);
at play()doc fifth 参数 loop
取0(= no loop)或-1(= loop forever)
用return true;
替换return false;
。获得ACTION_UP
的唯一方法是返回true
来告知Android系统,您将处理整个onClick
事件。