How to set Media Controller over the video?
Asked Answered
L

1

6

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);
    }
}
Leveridge answered 27/8, 2013 at 9:10 Comment(0)
I
6

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);
Inherit answered 27/8, 2013 at 9:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.