Resize video review

I am trying to dynamically set the size of an Android VideoView. I watched StackOverflow as well as the Internet; and the best solution I found was here . I performed my implementation below:

public class ResizableVideoView extends VideoView { public ResizableVideoView(Context c) { super(c); } private int mVideoWidth = 100; private int mVideoHeight = 100; public void changeVideoSize(int width, int height) { mVideoWidth = width; mVideoHeight = height; // not sure whether it is useful or not but safe to do so getHolder().setFixedSize(width, height); forceLayout(); invalidate(); // very important, so that onMeasure will be triggered } public void onMeasure(int specwidth, int specheight) { Log.i("onMeasure","On Measure has been called"); setMeasuredDimension(mVideoWidth, mVideoHeight); } public void onDraw(Canvas c) { super.onDraw(c); Log.i("onDraw","Drawing..."); } } 

The video changes correctly on the Android emulator, as well as on the Motorola Droid X; but on a Motorola Droid, the VideoView resizes, but the video played in the VideoView does not change. On a Motorola Droid, if VideoView is set to a larger size than video playback, a black background appears in the VideoView with video playback in the upper left corner of the video review over a black background.

How to change VideoView on Android correctly?

Thanks, Vance

+8
android android-widget videoview
source share
1 answer

My implementation works as follows:

 RelativeLayout.LayoutParams videoviewlp = new RelativeLayout.LayoutParams(newwidth, newheight); videoviewlp.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); videoviewlp.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); videoview.setLayoutParams(videoviewlp); videoview.invalidate(); 

With an invalid video image, you make it redraw the entire video using the new LayoutParams (and new dimensions).

+3
source share

All Articles