【发布时间】:2014-04-04 11:22:10
【问题描述】:
当我触摸图像时,媒体播放器启动,但从该图像中删除手指时,媒体播放不会停止。请帮帮我。
iv.setOnTouchListener(this); mp1 = MediaPlayer.create(getApplicationContext(), R.raw.air);
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
mp1 = MediaPlayer.create(getApplicationContext(), R.raw.airhorn_1);
mp1.start();
mp1.setLooping(true);
mp1.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp1) {
// TODO Auto-generated method stub
mp1.release();
}
});
Log.i("Action", "Down");
break;
case MotionEvent.ACTION_MOVE:
Log.i("Action", "Move");
Log.i("On Long", "On Long");
break;
case MotionEvent.ACTION_CANCEL:
mp1.pause();
Log.i("Action", "Cancel");
break;
case MotionEvent.ACTION_UP:
mp1.pause();
//mp1.stop();
Log.i("Action", "up");
break;
default:
break;
}
return true;
}
【问题讨论】:
-
你应该可以调用 mp1.stop(),这不工作吗?试试 mp1.stop(); mp1.release(); mp1 = 空;在 Action Up 上完全释放它。
-
当我抬起手指一段时间时,它不会停止。但有时它会停止。
-
双击时出错。
-
尝试使用 .IsPlayingMethod 检查它是否正在播放,如果是停止它。我会在支票上添加一个答案。