Android MediaController 拦截所有其他触摸事件

发布于 12-12 03:38 字数 248 浏览 0 评论 0原文

我的应用程序的上半部分有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

格子衫的從容2024-12-19 03:38:22

您可以查看我关于重写dispatchTouchEvent()以通过<传递点击的答案code>MediaController 到底层 Button,但我猜测您使用 MediaController 的方式有问题。你能发布你的布局吗?

UPD:
事实上,打击一下。我刚刚查看了 MediaController 代码,结果它创建了一个新的 Window为了自己。这就是为什么您的点击不会被调度——它们被调度到另一个窗口。另外,据我所知 构造函数代码,如果您通过 xml 扩充 MediaController(即在布局文件中使用它,然后通过代码中的 id 找到它),它不会创建额外的 Window。这很奇怪,但我确信他们这样做是有原因的。

因此,解决方案是尝试在布局文件中使用 MediaController 或使用 CommonsWare 的解决方案。如果您尝试一下 xml 的话,请告诉我情况如何。

You can check out my answer on overriding dispatchTouchEvent() to pass clicks through MediaController to an underlying Button, 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 new Window 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 extra Window. 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.

半枫2024-12-19 03:38:22

对此有什么想法吗?

不要使用MediaController。创建您自己的控制器 UI,根据需要弹出并显示。虽然这个示例项目可能不再完全工作,因为我已经三年没有碰过了,但它表明你有自己的控制器面板,触摸一下就会弹出,然后消失。

Any idea around that?

Do not use MediaController. Create your own controller UI that you pop up and display as needed. While this sample project may no longer completely work, as I have not touched in three years, it demonstrates having your own controller panel that pops up on a touch and then goes away.

枕头说它不想醒2024-12-19 03:38:22

您能否提供您的 VideoView 实例化代码以及用于切换 MediaPlayers 的代码?

无论如何,我怀疑这是否能正常工作,因为 VideoView 实例化了自己的 MediaPlayer 并使用它来播放媒体。 (参见VideoView.java

您可能需要切换 VideoView 本身,或者使用您自己的 SurfaceView 子类构建 VideoView 的替代品。

Could you supply your VideoView instantiation code and the code you use to switch out the MediaPlayers?

In any case, I doubt this will work well because the VideoView instantiates its own MediaPlayer and uses it to play media. (see VideoView.java)

You would probably need to switch out the VideoView itself, or build a replacement for the VideoView using your own subclass of SurfaceView.

傲娇萝莉攻2024-12-19 03:38:22

我遇到了同样的问题,我的 UI 元素由于媒体播放器而被阻止,花了 5 个小时后我得到了解决方案,

我只需将 mediaPlayer.prepare() 替换为 mediaPlayer.prepareAsync();

I have face same issue, my UI element block due to media player, After spend 5 hours I got solution

I just replace mediaPlayer.prepare() to mediaPlayer.prepareAsync();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文