我正在尝试在视频视图中添加触摸手势,但我不知道如何添加快进和快退。
除了这两个外,我添加了其他控件
我使用onGestureListener
,但现在我认为我需要使用拖动侦听器进行转发,我不确定。
这是我的代码:
public class Video extends Activity implements OnGestureListener{
private GestureDetector gd;
private VideoView vidView;
int sec, eventaction;
long timd, timu;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
vidView = (VideoView)findViewById(R.id.videoView1);
String vidAddress = "file:///storage/emmc/Apple - iPhone 5s - The new Touch ID fingerprint identity sensor.mp4";
Uri vidUri = Uri.parse(vidAddress);
vidView.setVideoURI(vidUri);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
vidView.start();
//Creating GestureDetector Object
gd = new GestureDetector(this, this);
//Assiging value to ImageView Object
//Setting Default Image of the ImageView
}
@Override
public boolean onTouchEvent(MotionEvent event) {
//Registering TouchEvent with GestureDetector
return gd.onTouchEvent(event);
}
@Override
public void onBackPressed() {
//Destroying Activity
finish();
}
@Override
public boolean onDown(MotionEvent arg0) {
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//Defining Sensitivity
float sensitivity = 50;
//Swipe Up Check
if(e1.getY() - e2.getY() > sensitivity){
//Setting Image Resource to Up_Arrow on Swipe Up
return true;
}
//Swipe Down Check
if(e2.getY() - e1.getY() > sensitivity){
//Setting Image Resource to Down_Arrow on Swipe Down
return true;
}
//Swipe Left Check
if (e1.getX() - e2.getX() > sensitivity) {
//Setting Image Resource to Left_Arrow on Swipe Left
vidView.pause();
sec=vidView.getCurrentPosition();
vidView.seekTo(1000+sec);
vidView.start();
Toast.makeText(getApplicationContext(), "swipe left", Toast.LENGTH_LONG).show();
return true;
}
//Swipe Right Check
if (e2.getX() - e1.getX() > sensitivity) {
//Setting Image Resource to Right_Arrow on Swipe Right
//if(e1.getAction() == MotionEvent.ACTION_DOWN){
//while(e2.getAction() == MotionEvent.ACTION_UP){
vidView.pause();
sec=vidView.getCurrentPosition();
vidView.seekTo(1000+sec);
vidView.start();
Toast.makeText(getApplicationContext(), "swipe right", Toast.LENGTH_LONG).show();
return true;
} else {
//If some error occurrs, setting again to Default_Image (Actually it will never happen in this case)
return true;
}
}
@Override
public void onLongPress(MotionEvent arg0) { }
@Override
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) {
return false;
}
@Override
public void onShowPress(MotionEvent arg0) {
if(vidView.isPlaying()) {
vidView.pause();
}
else {
vidView.start();
}
}
@Override
public boolean onSingleTapUp(MotionEvent arg0) {
return false;
}