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
android android-widget videoview
Vance-turner
source share