Vignesh
Vignesh

Reputation: 2325

How to modify width of videoview programmatically

I created a video view in my activity, when the activity gets started, i want to modify the height and width of the video. How to do it?

This my code. I tried with simple layout params and frame layout nothing works for me

            final VideoView vvVideos = (VideoView) rootView.findViewById(R.id.videoView);
            MediaController mediacontroller = new MediaController(ctx);
        mediacontroller.setAnchorView(vvVideos);
        String videoFileName = videos.get(position);
            Uri video = Uri.parse("android.resource://" + packageName +"/"+R.raw.sample);
            vvVideos.setMediaController(mediacontroller);
            //LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,150);
            vvVideos.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,150));
            vvVideos.setVideoURI(video);
            vvVideos.requestFocus();
            vvVideos.setOnPreparedListener(new OnPreparedListener() {
                // Close the progress bar and play the video
                public void onPrepared(MediaPlayer mp) {
                    //pDialog.dismiss();
                    vvVideos.start();
                }
            });    

The Solution

This code works for me....

            LayoutParams params=vvVideos.getLayoutParams();
            params.height=150;
            vvVideos.setLayoutParams(params);

Upvotes: 9

Views: 15343

Answers (2)

Sagar Maiyad
Sagar Maiyad

Reputation: 12733

VideoView videoview=(VideoView) findViewById(R.id.videoView1);
videoview.setVideoURI("yourURI");
videoview.setLayoutParams(new FrameLayout.LayoutParams(550,550));

LinearLayout linearLayout = (LinearLayout)findViewById(R.id.info)
linearLayout.addView(videoview);

Upvotes: 0

Jibran Khan
Jibran Khan

Reputation: 3256

Try this, it works for me

VideoView video=(VideoView) findViewById(R.id.videoView1);
        video.setVideoURI(setVideoUri());
        video.setVisibility(View.VISIBLE);
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)video.getLayoutParams();
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
        layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, 0);
        video.setLayoutParams(layoutParams);

Upvotes: 4

Related Questions