0

I have a video in a videoview that plays and loops as the background of my login/register activity. The video plays and loops fine except it does not cover the entire screen. The activity is locked in portrait mode but the video only displays on the lower half of the screen (as if in landscape mode). The videoview itself does cover the entire screen. This is my current code.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);

    VideoView videoView = (VideoView) findViewById(R.id.launcherVideo);
    Uri src = Uri.parse("android.resource://com.package/raw/video");
    videoView.setVideoURI(src);

    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {

            mp.setVolume(0, 0);
            mp.setLooping(true);
        }
    });

    //videoView.setMediaController(new MediaController(this));

    videoView.start();
}

This is my xml

<VideoView
    android:id="@+id/launcherVideo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/linearLayout" />

How do I make the video full screen on any size device?

Skankhunt42
  • 3
  • 1
  • 7

3 Answers3

2

Having not seen the entire layout xml, I guess this may help.

Try wrapping your VideoView with a RelativeLayout and align it to the parent:

<VideoView
    android:id="@+id/launcherVideo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true">
Attacktive
  • 604
  • 1
  • 11
  • 25
0
  <RelativeLayout
            android:id="@+id/video_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/progress_limit">

            <com.example.FullScreenVideoView
                android:id="@+id/video_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentTop="true"
                android:layout_alignParentBottom="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentStart="true"/>
            <ProgressBar
                android:id="@+id/progress"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:indeterminate="false"
                android:layout_centerInParent="true"
                 />
        </RelativeLayout>

And also use this code it have worked for me

public class FullScreenVideoView extends VideoView {
    public FullScreenVideoView(Context context) {
        super(context);
    }

    public FullScreenVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

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

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
    }
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
Vijendra patidar
  • 1,444
  • 1
  • 14
  • 24
-1

You can try to use TextureView instead of VideoView as this answer describe

Community
  • 1
  • 1
mr.icetea
  • 2,607
  • 3
  • 24
  • 42