15

I am currently trying to implement a videoview that will show a video on a specific position. I can show a fullscreen video with no problem. However whenever i try to show that video inside a frame( a little rectangle for example ) I can only show a part of video in that view. I couldn't fit the video into that view.

I already look for lots of links about scaling a video in android, however I couldnt find any way to do this. Any help about that issue will be helpful.

What i am using is i have 2 different classes. One of them is my video activity class and other one is a helper class:

public class VideoViewCustom extends VideoView {
    private int mForceHeight = 0;
    private int mForceWidth = 0;
    public VideoViewCustom(Context context) {
        super(context);
    }     
    public VideoViewCustom(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public VideoViewCustom(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void setDimensions(int w, int h) {
        this.mForceHeight = h;
        this.mForceWidth = w;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
         setMeasuredDimension(mForceWidth, mForceHeight);
    }
}

That class help me to set dimensions of videoview correctly, however i couldnt make video fit into that region. I mean I couldn't scale the video to fit into that region. I dont know whether or not android is autoscaling into given dimensions but i couldnt do it.

denizt
  • 713
  • 5
  • 21
  • http://stackoverflow.com/questions/4434027/android-videoview-orientation-change-with-buffered-video This link may be useful for you – Thiru VT May 17 '12 at 10:40
  • I already go over it but it make no difference. Dunno why tough – denizt May 17 '12 at 11:24
  • 2
    Well I fixed this issue with porting my application to ICS. In ICS it work without a problem. However when I was trying to do that with Froyo, I came through lots of problems. I ll go over them if someone also faces with them. – denizt Jun 19 '12 at 06:08
  • First problem was about fitting different video types into a region. This was because of the videoplayer android using. I change my videoplayer type from android source code and then .avi, .mov and .mp4 start to fit into specified coordinates. However with my kernel version on 2.2 I cant play more than one video at the same time. That is why i ported my application into ICS. In ICS I can play more than one video at the same time without a problem. – denizt Jun 19 '12 at 06:09

2 Answers2

2

May this will help you...

public void onMeasure(int width, int height)
{
    getHolder().setFixedSize(width, height);
    forceLayout();
            setMeasuredDimension(width, height);
    invalidate();
}

...and try a RelativeLayout

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <VideoView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentLeft="true"/>

</RelativeLayout>
Carsten Drösser
  • 496
  • 1
  • 4
  • 16
1

I think you have to create a ViewGroup where you can implements onLayout() method.

Here you can set the position of your views directly calling the layout() method for each one of them.

Example:

ViewGroup vg = new ViewGroup(this) {

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
            int x = getMeasuredWidth();
            int y = getMeasuredHeight();
            for (int i = 0; i < vg.getChildCount(); i++) {
                if(vg.getChildAt(i) instanceof TextView){
                    vg.getChildAt(i).layout(...);//and so on...

                }
            }
        }
};

Hope helping!!

Oibaf it
  • 1,842
  • 16
  • 9