Just Variable
Just Variable

Reputation: 877

VideoView content resize

I have a VideoView which is set to fill parent and works fine with full size videos ,I am finding it difficult to find a solution when video size is 4:3 or smaller it keeps to left of my view whereas same application in ios display's it in full screen. Can we resize the video and show it with same size of that of a Video View?or can content of VideoView resized? I tried

view.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);

but no results

Upvotes: 0

Views: 5895

Answers (1)

Iulia Barbu
Iulia Barbu

Reputation: 1530

Make a custom video class like this:

public class CustomVideoView extends VideoView {

    protected int _overrideWidth = 480;

    protected int _overrideHeight = 360;

    public CustomVideoView(Context context) {
        super(context);
    }

    public CustomVideoView(Context context, AttributeSet set) {
        super(context, set);
    }

    public void resizeVideo(int width, int height) {
        _overrideHeight = height;
        _overrideWidth = width;
        // not sure whether it is useful or not but safe to do so
        getHolder().setFixedSize(width, height);
        //getHolder().setSizeFromLayout();
        requestLayout();
        invalidate(); // very important, so that onMeasure will be triggered

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        setMeasuredDimension(_overrideWidth, _overrideHeight);
    }

}

In your class use the resizeVideo method with the screen width and height as parameters.

Take in account that all depends on the movie ratio and the screen ratio. If they are the same, than the video is displayed full screen, but when they are different, the video is adjusted on width/height.

Upvotes: 5

Related Questions