Android:为什么我不能为 VideoView 提供 onClickListener?
我已经编写了这些代码行:
mVideoView = (VideoView) findViewById(R.id.video_view);
mVideoView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.v("LOG_TAG, click");
}
});
但是,当我运行我的应用程序时,永远不会调用单击事件。
所以我想知道,是否不可能在 VideoView 上注册 OnClickListener ?如果是这样,为什么会这样?
I have written 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 run my application, the click event is never called.
So I wonder, is it impossible to register an OnClickListener on a VideoView? And, if so, why is that the case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
使用
VideoView.setOnTouchListener(..)
它适用于 VideoViewuse
VideoView.setOnTouchListener(..)
it works for VideoView以下是我如何使用 onTouch 解决 VideoViews 的暂停/播放问题:
Here's how I solved the pause/play of VideoViews using onTouch:
我知道这很旧,但我用过这个:
I know this is old but I used this:
我知道这是一个老问题,但这是我所做的:
由于 setOnClickListener 没有被触发,我创建了自己的类,它扩展了 VideoView
并覆盖了 onTouchEvent
,现在我可以使用 MotionEvent 获取 onClick 事件。
希望这对某人有帮助!
I know this is and old question, but here is what I did:
Since setOnClickListener is not been triggered, I created my own class which extends VideoView
and Overrided the onTouchEvent
and now I can get the onClick event with the MotionEvent.
Hope this helps someone!
这可能早就该发生了,尽管如此,对于那些可能遇到类似问题的人来说还是有一些帮助的。我解决这个问题的方法是在视频视图的顶部放置一个透明的图像视图,然后监听图像视图上的 onClick 事件,然后对视频视图执行我想要执行的任何操作。
This is probably long overdue, nonetheless of some help to those who may run into a similar problem. The way I got around this problem was by laying a transparent image view right on top of the video view, then listening to onClick events on the image view, and doing whatever it was I wanted to do with the video view afterwards.
我意识到这是一个老问题,但我想我会提出一个简单的解决方法。我无法回答为什么这不起作用 - 在我看来这似乎是一个很大的疏忽。但一个简单的解决方法是将 VideoView 作为 FrameLayout 内的唯一 View,并在布局上设置 OnClickListener。不理想,但它有效。
I realize this is an old question but thought I'd chime in with an easy workaround. I can't answer why this doesn't work - seems like a big oversight in my opinion. But an easy workaround is to place your VideoView as the sole View inside a FrameLayout, and set an OnClickListener on the layout. Not ideal, but it works.
如果您希望通过触摸视频的特定部分来执行某些操作,您可以使用在视频视图上透明的按钮。
You can well use a button which is transparent on the video view if you want a specific part of the video on touch to do something.
您可以通过封面布局来解决这个问题。
我使用了线性布局。
并在源文件中尝试。
You can solve this issue through cover layout.
I used the linearlayout.
and try it in source file.
VideoView 是包含 MediaPlayer 和 SurfaceView 的包装器。您可以通过 MediaController 进行交互或编写自己的 SurfaceView 并实现 onClick 事件。
The VideoView is a wrapper containing MediaPlayer and SurfaceView. You can interact with through MediaController or writing your own SurfaceView and implement onClick events.
您可以尝试 手势叠加视图
您应该能够将此视图叠加到另一个视图的顶部以获得触摸事件。
希望这有帮助!
You might try Gesture Overlay View
You should be able to overlay this view on top of another view in order to get touch events.
Hope this helps!
我可能已经用 onSetClickListener 做到了这一点。这是为您提供帮助的代码:
It is possible I have did this with onSetClickListener. And Here's a code for your help: