Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i view a video inside a videoview at some specific position?

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.

like image 269
denizt Avatar asked May 17 '12 10:05

denizt


People also ask

How do I make Android videos full screen?

Tap the video you'd like to watch. At the bottom of the video player, tap full screen .


1 Answers

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>
like image 172
Carsten Drösser Avatar answered Nov 09 '22 21:11

Carsten Drösser