Android: Why can't I give onClickListener for VideoView?

I wrote these lines of code:

mVideoView = (VideoView) findViewById(R.id.video_view); mVideoView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Log.v("LOG_TAG, click"); } }); 

However, when I launch my application, the click event is never raised.

So, I wonder if it is not possible to register OnClickListener in VideoView? And if so, why is this so?

+50
android videoview
May 30 '11 at 11:04
source share
10 answers

use VideoView.setOnTouchListener(..) it works for VideoView

+71
Jun 30 '11 at 19:36
source share

Here's how I decided to pause / play VideoViews using onTouch:

 // Class variables private boolean bVideoIsBeingTouched = false; private Handler mHandler = new Handler(); vvVideo.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (!bVideoIsBeingTouched) { bVideoIsBeingTouched = true; if (vvVideo.isPlaying()) { vvVideo.pause(); } else { vvVideo.resume(); } mHandler.postDelayed(new Runnable() { public void run() { bVideoIsBeingTouched = false; } }, 100); } return true; } }); 
+13
Jan 4 '13 at 19:04 on
source share

I know this is old, but I used this:

  mVideoView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { Log.i(TAG, "Video 1 clicked, starting playback"); return false; } }); 
+13
Jan 05 '13 at 3:24
source share

I know this is an old question, but here is what I did:

Since setOnClickListener does not start, I created my own class that extends VideoView

 public class VideoViewCustom extends VideoView{ 

and override onTouchEvent

 @Override public boolean onTouchEvent(MotionEvent ev) { if(ev.getAction() == MotionEvent.ACTION_DOWN){ Log.d(TAG, "ACTION_DOWN"); } return super.onTouchEvent(ev); } 

and now I can get the onClick event with MotionEvent.

Hope this helps someone!

+12
Aug 12 '13 at 9:56
source share

This is probably long overdue, however, some help to those who may encounter a similar problem. The way I ran into this problem was to lay a transparent view of the image directly above the video image, then listen to the onClick events on the image and do what I wanted to do with watching the video later.

+2
Apr 10 2018-12-12T00:
source share

I understand this is an old question, but I thought I would try with an easy workaround. I can not answer why this does not work. In my opinion, this is a lot of supervision. But an easy workaround is to place your VideoView as the only view inside FrameLayout and set OnClickListener in the layout. Not perfect, but it works.

+2
Mar 13 '15 at 19:22
source share

You can use the button that is transparent on the video if you want some part of the video to touch in order to do something.

+1
Nov 09 '13 at 4:11
source share

VideoView is a wrapper containing mdeiaplayer and surfaceView. You can interact through MediaController or write your own SurfaceView and implement onClick events.

0
May 30 '11 at 12:41
source share

You can try viewing gesture overlays.

You can overlay this view on top of another view to get touch events.

Hope this helps!

0
Jun 30 '11 at 19:44
source share

Perhaps I did this using onSetClickListener. And here is the code for your help:

 mVideoView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //Here you put a condition for playing a video when you click on your video view.// if(my_video.isPressed()) { my_video.start(); } else { Toast.makeText(getApplicationContext(), "Not able to run This Video!", Toast.LENGTH_LONG).show(); } } }); 
-3
Jun 05 '12 at 6:25
source share



All Articles