Android MediaController intercepts all other touch events
Asked Answered
P

4

9

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?

Perea answered 26/10, 2011 at 22:16 Comment(3)
Could you give us an idea of what your application's layout XML looks like?Retribution
I didn't start this bounty btw. I'd have to dig through my projects to find the XMLPerea
There's a strongly similar question: #12022617 but since no answer has been accepted there, flagging this one duplicate doesn't make sense.Bartolemo
B
12

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.

Bartolemo answered 17/9, 2012 at 14:12 Comment(6)
Media controller "The way to use this class is to instantiate it programatically ". Using it in a layout seems to cause a crash with a null pointer exceptionBriarroot
@Briarroot Functions like show() and hide() have no effect when MediaController is created in an xml layout – so that scenario is also a valid one. Also, they would have not made the constructor for xml in the first place. At what point does the NPE occur?Bartolemo
It was crashing during setAnchorView. I removed it, but now it doesn't displayBriarroot
same problem here Casebash - did you find a solution?Mazer
@IvanBartsov Thanx for pointing this out... I cannot even believe 'MediaController' is so badly designed...Uruguay
@smitalm Ah, the awesome feeling of still receiving thanks half a year later... Glad I could help, make sure to upvote the answer ;)Bartolemo
O
8

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.

Outmarch answered 16/9, 2012 at 17:21 Comment(2)
Is that a recommendation to avoid using MediaController in general, or just in situations where one needs the UI beneath it to continue functioning?Humperdinck
@Spinner: Well, it definitely needs to be avoided if you want clicks on the rest of the UI to work. Beyond that, last I checked, MediaController was kinda lame from a UI and functionality standpoint, anyway, so you're probably better off with something else. That being said, if you don't mind MediaController being effectively modal, and you want to use it, go right ahead.Outmarch
S
1

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.

Selfdeceit answered 16/9, 2012 at 3:28 Comment(0)
G
0

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();

Galiot answered 30/7, 2016 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.