1
votes

I am trying to make the video player i.e. Exoplayer to go fullscreen on Button Click but unfortunately, I am not able to do so as the player covers half of the screen only.

Attaching screenshots of how the Player looks in Landscape mode: The Player covers half the screen instead of covering full screen

Anyone out there who can help me out. Thanks in advance

player.xml

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
  <ScrollView
    android:layout_width="match_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.4"
            android:orientation="vertical"
            android:background="#FFFFFF"
            android:id="@+id/name">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:id="@+id/textholder">
              <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="12dp"
                    android:layout_marginTop="20dp"
                    android:text="This is a Dummy text to implement Scroll View in this application"
                    android:textColor="#424242"
                    android:textSize="50sp"
                    android:textStyle="bold"
                    android:id="@+id/text"
                   />
            </LinearLayout>
       </LinearLayout>
        <FrameLayout
            android:id="@+id/main_media_frame"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="#000000">

            <com.google.android.exoplayer2.ui.PlayerView
                android:id="@+id/player_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="fill" >
            </com.google.android.exoplayer2.ui.PlayerView>
        </FrameLayout>
        <LinearLayout
            android:id="@+id/videoDetailsLayout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.52"
            android:orientation="vertical"
            android:background="#FFFFFF">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:id="@+id/vd">
                <TextView
                    android:id="@+id/VideoName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="12dp"
                    android:layout_marginTop="20dp"
                    android:text="Big Buck Bunny"
                    android:textColor="#424242"
                    android:textSize="18sp"
                    android:textStyle="bold"
                    />
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="10dp"
                android:orientation="vertical"
                android:id="@+id/videoDetailsLayoutd">
                <TextView
                    android:id="@+id/vast_tag_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="12dp"
                    android:layout_marginTop="20dp"
                    android:text="Vast Tags"
                    android:textColor="#424242"
                    android:textSize="18sp"
                    android:textStyle="bold"
                    />
                <TextView
                    android:id="@+id/vast_tags"
                    android:layout_width="wrap_content"
                    android:layout_height="400dp"
                    android:layout_marginLeft="12dp"
                    android:layout_marginTop="20dp"
                    android:textColor="#424242"
                    android:textSize="18sp"
                    />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</ScrollView>

Code for FullScreen:

private void openFullscreenDialog() {

    videoDetailsLayout.setVisibility(LinearLayout.GONE);
    vast_tags.setVisibility(LinearLayout.GONE);
    name.setVisibility(LinearLayout.GONE);

    ((ViewGroup) playerView.getParent()).setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION //hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN //hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE);

    mFullScreenIcon.setImageDrawable(ContextCompat.getDrawable(PlayerActivity.this, R.drawable.ic_fullscreen_shrink));
    mExoPlayerFullscreen = true;
    //For explicitly changing the Orientation to Landscape
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    try {
        vast_tags.append("Fullscreen \n");
        videoEvents.playerStateChange(PlayerState.FULLSCREEN);
    } catch (Exception e) {
        Logger.d("Error is " + e.getMessage());
    }
}
1

1 Answers

0
votes

Your exoplayer is inside a FrameLayout which has a fixed height of 200dp. When you put match_parent as the height attrib for exoplayer, it means fill the height of its immediate parent, which in this case is the 200dp FrameLayout.

One way to solve this is to change the height of exoplayer's parent to match_parent. But since the layout is not structured optimally you would need to tweak a lot keeping the same layout. I would suggest you give a read to the following link on simple linear layout design to get a better understanding.