0

I want to put my video on fullscreen mode with a click of a button. My app works fine, and it plays a video along the the media controls, play, pause, rewind, and go forward. However, I am unaware of making the video full screen with a button. Please help! I am using android studio.

This is my Java code-

package com.example.lenovouser.video;


import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {

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

    VideoView videoView = findViewById(R.id.video_view);
    String videoPath = "android.resource://" + getPackageName() + "/" + 
    R.raw.surf;
    Uri uri = Uri.parse(videoPath);
    videoView.setVideoURI(uri);

    MediaController mediaController = new MediaController(this);
    videoView.setMediaController(mediaController);
    mediaController.setAnchorView(videoView);




    }
}

This is my xml code-

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.lenovouser.video.MainActivity">

<FrameLayout
    android:id="@+id/frameLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="130dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/button">

    <VideoView
        android:id="@+id/video_view"
        android:layout_width="match_parent"
        android:layout_height="250dp" />

</FrameLayout>

<Button
    android:id="@+id/button"
    android:layout_width="322dp"
    android:layout_height="145dp"
    android:layout_marginTop="35dp"
    android:layout_marginBottom="38dp"
    android:text="FULLSCREEN"
    app:layout_constraintBottom_toTopOf="@+id/frameLayout"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

My video I chose is in mp4 format, so it is compatible with android studio.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 1
    Possible duplicate of [VideoView Full screen in android application](https://stackoverflow.com/questions/11310764/videoview-full-screen-in-android-application) – Jonathan Gagne Oct 22 '18 at 10:36

1 Answers1

0

Add this to your theme in styles

<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>

OR

Use the following example to make activity fullscreen

public class ActivityName extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // remove title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}
Nazarii Moshenskiy
  • 1,802
  • 2
  • 16
  • 35