我正在使用以下代码:
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
//finish();
}
});
videoView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (videoView.isPlaying()) {
videoView.pause();
finish();
}
return true;
}
});
我遇到一个问题:当触发onCompletion时,应用程序将关闭atm。我希望它只在我再次触摸videoView时关闭,但是在onCompletion被触发后,onTouch将不会再次触发。
在onCompletion被触发后,我该怎样做才能再次启用onTouch?
答案 0 :(得分:0)
您可以使用onCompletion
的标记。
boolean mVideoCompleted = false;
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
mVideoCompleted = true;
}
});
videoView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (mVideoCompleted) {
finish();
}
if (videoView.isPlaying()) {
videoView.pause();
finish();
}
return true;
}
});