MediaController Positioning - bind to VideoView
android, android-layout, android-videoview, android-view, mediacontroller
Solution
I ended up by doing a dirty hack... i just manually attached the view to my `videoView` to achieve the wanted behavior:
public void onPrepared(MediaPlayer mp) {
MediaController mc = new MediaController(videoView.getContext(), false);
// set correct height
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoView.getLayoutParams();
params.height = mp.getVideoHeight();
videoView.setLayoutParams(params);
videoView.setMediaController(mc);
pBar.setVisibility(View.GONE);
mc.show(0);
FrameLayout f = (FrameLayout) mc.getParent();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_BOTTOM, videoView.getId());
((LinearLayout) f.getParent()).removeView(f);
((RelativeLayout) videoView.getParent()).addView(f, lp);
mc.setAnchorView(videoView);
}
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 the `MediaController` as it's supposed to.
There definitly is a much better solution and hopefully someone can give me a hint!
Problem
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`?