There have been a lot of discussions about how to position a MediaController
and most answers are to use the setAnchorView
-Method. At the first glance this solution seems to work but in my case it doesn't.
According to this Post setAnchorView
only acts as a reference for initial positioning of the MediaController
, but actually creates a new floating Window
on top.
So what I want is a MediaController
that is really bound to a parent View
(e.g. VideoView).
For example if you have a LinearLayout
within a ScrollView
and you have to scroll down to your VideoView
where the MediaController
is attached to, the MediaController
should really be attached to this VideoView
so that the MediaController
scrolls along with the VideoView
.
Another Use-Case where this problem accurs is discussed here, where the MediaController
is used within a ViewPager
.
So how to achieve such a behavior for a MediaController
?
I ended up by doing a dirty hack... i just manually attached the view to my
videoView
to achieve the wanted behavior:the problem with this solution is, that setting the anchorView doesn't have any effect and therefore tapping on the
VideoView
doesn't hide/show theMediaController
as it's supposed to.There definitly is a much better solution and hopefully someone can give me a hint!
To convert Jonathan Hockman's answer to Java and add it to DERIIIFranz's answer:
For the videoView:
Just wanted to add to DERIIIFranz's answer. I used the same method to assign the media controller to the view I wanted and to get the Hide() and Show() functions to work properly I simply made my own MediaController class and overrode the Hide() and Show() methods as well as the isShowing property (I'm doing this in C# with Xamarin, so I don't know what issues you would have with Java).
I also added my own click listener on the VideoView to ensure that I could handle the Hide() and Show() events myself.