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?

Ronnie
  • 11,138
  • 21
  • 78
  • 140
  • 1
    Could you give us an idea of what your application's layout XML looks like? – alanv Sep 12 '12 at 07:33
  • I didn't start this bounty btw. I'd have to dig through my projects to find the XML – Ronnie Sep 12 '12 at 16:26
  • There's a strongly similar question: http://stackoverflow.com/questions/12022117/add-view-on-top-of-mediacontroller but since no answer has been accepted there, flagging this one duplicate doesn't make sense. – Ivan Bartsov Sep 17 '12 at 14:15

4 Answers4

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.

Community
  • 1
  • 1
Ivan Bartsov
  • 19,664
  • 7
  • 61
  • 59
  • 1
    [Media controller](http://developer.android.com/reference/android/widget/MediaController.html) "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 exception – Casebash Sep 24 '12 at 04:40
  • 1
    @Casebash _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? – Ivan Bartsov Sep 24 '12 at 10:12
  • 2
    It was crashing during `setAnchorView`. I removed it, but now it doesn't display – Casebash Sep 24 '12 at 12:16
  • same problem here Casebash - did you find a solution? – dorjeduck Oct 13 '12 at 18:26
  • @IvanBartsov Thanx for pointing this out... I cannot even believe 'MediaController' is so badly designed... – hendrix Mar 28 '13 at 16:14
  • 1
    @smitalm Ah, the awesome feeling of still receiving thanks half a year later... Glad I could help, make sure to upvote the answer ;) – Ivan Bartsov Mar 29 '13 at 10:24
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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Is that a recommendation to avoid using `MediaController` in general, or just in situations where one needs the UI beneath it to continue functioning? – Spinner Jul 09 '14 at 11:28
  • 1
    @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. – CommonsWare Jul 09 '14 at 11:30
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.

Rishabh Agrawal
  • 861
  • 2
  • 15
  • 25
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();

shubomb
  • 672
  • 7
  • 20