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.
Tap the video you'd like to watch. At the bottom of the video player, tap full screen .
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With