1

I want my video activity to go fullscreen when the video starts, but it's not happening. Here are some screenshots and the code that runs this activity.:

public class InfoLentes extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.infolentes);
    }

    public void sendMessage(View view) {

       setContentView(R.layout.fullscreen);
        VideoView VideoView = new VideoView(this);
        getWindow().setFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        VideoView.setMediaController(new MediaController(this));
        Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
                + R.raw.eyeprotect);
        VideoView.setVideoURI(video);
        setContentView(VideoView);
        VideoView.start();

    }

}

And this is my fullscreem.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent">

    <VideoView
        android:id="@+id/VideoViewfull"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </VideoView>

</FrameLayout>

And Screenshots of whats happening.:

enter image description here

What am I doing wrong?

EDIT:

So Using @Sheetal Kumar Maurya answer, I created another activity and used the android:theme="@style/AppTheme.NoActionBar" on the manifest, the result is better, but still not really fullscreen.:

enter image description here

Zoe
  • 27,060
  • 21
  • 118
  • 148
Luis
  • 123
  • 1
  • 3
  • 18

2 Answers2

0

Create a VideoPlayer activity with NoActionbar theme.

<activity
        android:name=".VideoPlayerActivity"
        android:theme="@style/AppTheme.NoActionBar" />

In onCreate section add following:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

Now use this activity as a player for full screen and enjoy.

  • So, using the requestWindow like I was doing, in the onCreate inside the activity which contains the button for the video, is wrong? – Luis Feb 15 '19 at 18:39
0

So I finally, after a long time of searching, found the perfect solution for my problem. Using the answer here on this post from @Hamiseixas, I did the following.:

Edited Gradle, and synced:

compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.2'


repositories {
        mavenCentral()
    }

Instead of a videoview, I used the new compiled package on my fullscreen.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_alignParentRight="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_alignParentBottom="true"
                android:layout_height="fill_parent">

    <com.github.rtoshiro.view.video.FullscreenVideoLayout
        android:id="@+id/videoview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </com.github.rtoshiro.view.video.FullscreenVideoLayout>
</RelativeLayout>

And when I press the intent button to take me to the video file I want to play, this is the activity that playes it.:

import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.github.rtoshiro.view.video.FullscreenVideoLayout;

import java.io.IOException;

public class VideoTest extends AppCompatActivity {

    FullscreenVideoLayout videoLayout;

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

        videoLayout = (FullscreenVideoLayout) findViewById(R.id.videoview);
        videoLayout.setActivity(this);

        Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
                + R.raw.eyeprotect);
        try {
            videoLayout.setVideoURI(video);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }
}

It was that simple =D

It's all better documented here, a huge thanks to that post, and to the creator of FullscreenVideoView, Toshiro

Luis
  • 123
  • 1
  • 3
  • 18