Android MediaController 拦截所有其他触摸事件
我的应用程序的上半部分有一个 VideoView
,其下有一个 MediaController
。下半部分是带有一些按钮的图像。虽然 MediaController
可见,但下面的按钮不可单击。就像当 MediaController
可见时,它会拦截所有其他触摸事件,即使它们不在 MediaController
的范围内。
有什么想法吗?
The top half of my app has a VideoView
with a MediaController
under it. The bottom half is an image with some buttons. While the MediaController
is visible, the buttons below are not clickable. It's like while the MediaController
is visible, it intercepts all other touch events, even if they are not within the bounds of the MediaController
.
Any idea around that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(4)
您能否提供您的 VideoView 实例化代码以及用于切换 MediaPlayers 的代码?
无论如何,我怀疑这是否能正常工作,因为 VideoView 实例化了自己的 MediaPlayer 并使用它来播放媒体。 (参见VideoView.java)
您可能需要切换 VideoView 本身,或者使用您自己的 SurfaceView 子类构建 VideoView 的替代品。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以查看我关于重写dispatchTouchEvent()
以通过<传递点击的答案code>MediaController 到底层Button
,但我猜测您使用 MediaController 的方式有问题。你能发布你的布局吗?UPD:
事实上,打击一下。我刚刚查看了
MediaController
代码,结果它创建了一个新的Window
为了自己。这就是为什么您的点击不会被调度——它们被调度到另一个窗口。另外,据我所知 构造函数代码,如果您通过 xml 扩充 MediaController(即在布局文件中使用它,然后通过代码中的 id 找到它),它不会创建额外的Window
。这很奇怪,但我确信他们这样做是有原因的。因此,解决方案是尝试在布局文件中使用 MediaController 或使用 CommonsWare 的解决方案。如果您尝试一下 xml 的话,请告诉我情况如何。
You can check out my answer on overridingdispatchTouchEvent()
to pass clicks throughMediaController
to an underlyingButton
, but I'm guessing there's something wrong with the way you use MediaController. Can you post your layout?UPD:
Actually, strike that. I've just taken a look at
MediaController
code and it turns out it creates a newWindow
for itself. That's why your clicks don't get dispatched — they're dispatched to another window. Also, as far as I can tell from the constructor code, if you inflate the MediaController via xml (i.e. use it in a layout file and then just find it by id from you code) — it won't create the extraWindow
. That's weird, but I'm sure they had reasons for that.So, the solution is to either try to use MediaController in a layout file or go with CommonsWare's solution. Please, let me know how it goes in case you give the xml thing a try.