How to set Media Controller over the video?

11.4k views Asked by At

I created simple video view application it's working fine. I have added layoutparams to video view and added videoview into one layout position, that time my media controller showing out of the region but i wish to show media controller over the video.Please give me your useful suggestions.

screen shot: enter image description here

code:

public class MainActivity extends Activity {
    private VideoView view;
    RelativeLayout layoutmain, layout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        layoutmain = (RelativeLayout) findViewById(R.id.id1);
        MediaController controller = new MediaController(this);
        view = new VideoView(this);
        view.setVideoPath("/mnt/sdcard/jj.avi");
        RelativeLayout.LayoutParams viewparam = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
        viewparam.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        viewparam.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        viewparam.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        viewparam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        view.setLayoutParams(viewparam);
        FrameLayout.LayoutParams viewparam1 = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        controller.setLayoutParams(viewparam1);
        view.setMediaController(controller);
        controller.setAnchorView(controller);
        view.requestFocus();
        view.start();
        try {
            layout = new RelativeLayout(this);
            RelativeLayout.LayoutParams viewparam2 = new RelativeLayout.LayoutParams(500, 500);
            viewparam2.setMargins(20, 20, 0, 0);
            layout.setLayoutParams(viewparam2);
            layout.setBackgroundColor(Color.BLACK);
            layout.addView(view);
            layout.addView(controller);
        } catch (Exception e) {
            e.printStackTrace();
        }
        layoutmain.addView(layout);
    }
}
1

There are 1 answers

0
Ali Imran On BEST ANSWER

Create a view in xml where you want to put the controller, then in code write like this

View v = findViewById(R.Id.yourView); 

controller.setAnchorView(v);