MediaController positioning over VideoView
Setting the anchor view will only work if the videoview size is known - it will not be upon init. But you can do something like this:
video.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
/*
* add media controller
*/
mc = new MediaController(YourActivity.this);
video.setMediaController(mc);
/*
* and set its position on screen
*/
mc.setAnchorView(video);
}
});
}
});
I found really easy solution.
Just wrap the videoView in a FrameLayout then you can add the MediaController to that FrameLayout from code, like this:
MediaController mc = new MediaController(context);
videoView.setMediaController(mc);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.BOTTOM;
mc.setLayoutParams(lp);
((ViewGroup) mc.getParent()).removeView(mc);
((FrameLayout) findViewById(R.id.videoViewWrapper)).addView(mc);
EDIT: since I posted this answer I ran into a lot of issues with getting it to hide and with controlling its size so what I ended up doing was I just created my own layout with controls that I could animate and work with without headaches