Extending MediaController for android

后端 未结 3 824
面向向阳花
面向向阳花 2020-12-06 07:53

I am using a VideoView and the MediaController for an app I am working on. I simply wanted to have the MediaController appear on top

3条回答
  •  失恋的感觉
    2020-12-06 08:26

    The preferred way to control the location of the MediaController is via setAnchorView. Unfortunately, the VideoView seems to override this value to be the parent view of itself whenever a new video is loaded. To counter act this, a class like the following should work

    public class ConstantAnchorMediaController extends MediaController
    {
    
        public ConstantAnchorMediaController(Context context, View anchor)
        {
            super(context);
            super.setAnchorView(anchor);
        }
    
        @Override
        public void setAnchorView(View view)
        {
            // Do nothing
        }
    }
    

    Once you do that, you can use this MediaController to set the Anchor to whichever view you desire without worrying about your VideoView changing it. After that, its just a matter of getting a view in the right place to anchor it too.

提交回复
热议问题