我试图让 Android 媒体播放器停止在这个 onTouch 方法中播放声音,但它不会。相反,它将声音作为最后一个声音的补充,所以我可以听到它们重叠。如果我让它循环,循环就不会停止。即使我不使用 isPlaying 部分但插入并检查布尔值,它也不起作用。有什么建议吗?
public boolean onTouch(View v, MotionEvent event){
mp = MediaPlayer.create(getBaseContext(), R.raw.tara);
if (event.getAction() == MotionEvent.ACTION_DOWN){
Drawable myIcon = getResources().getDrawable( R.drawable.image1);
getWindow().setBackgroundDrawable(myIcon);
if (mp.isPlaying()){
mp.stop();
}
else {
mp.start();
}
}
else if (event.getAction() == MotionEvent.ACTION_UP){
Drawable myIconup = getResources().getDrawable( R.drawable.image2);
getWindow().setBackgroundDrawable(myIconup);
}