如何使用视频进行全屏活动?

时间:2019-11-10 20:19:59

标签: android

我知道这个问题已经回答了很多次,但是某些设备上的全屏显示存在问题。

示例:

(很明显,导航栏是自动隐藏的。)

存在此问题的设备的纵横比为21:9(Motorola One Vision Android 9)。

enter image description here

enter image description here

带VLC的全屏显示

enter image description here

对于所有仿真器(并在S9 +,J5-6-7,Android TV中进行测试...),它都能完美运行:

enter image description here

在大多数设备(无论是电视,平板电脑还是任何设备)中,全屏模式都能完美体现。

我正在使用Android的VLC库。

XML代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/player_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:keepScreenOn="true"
    >

    <!--
     the double FrameLayout is necessary here to do cropping on the bottom right
     (which requires the surface not be centered), while keeping the result centered
    -->

    <org.videolan.libvlc.util.VLCVideoLayout
        android:id="@+id/video_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fitsSystemWindows="false">

    </org.videolan.libvlc.util.VLCVideoLayout>

    <androidx.appcompat.widget.ViewStubCompat
        android:id="@+id/player_info_stub"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginBottom="@dimen/default_margin"
        android:layout="@layout/player_overlay_info"/>

    <androidx.appcompat.widget.ViewStubCompat
        android:id="@+id/player_brillo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginBottom="@dimen/default_margin"
        android:layout="@layout/player_brillo"/>

    <androidx.appcompat.widget.ViewStubCompat
        android:id="@+id/buffer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginBottom="@dimen/default_margin"
        android:layout="@layout/player_buffer_info"/>
    <RelativeLayout
        android:id="@+id/player_ui_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <androidx.appcompat.widget.ViewStubCompat
            android:id="@+id/viewStub"
            android:focusable="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout="@layout/playerheader"
            android:layout_marginRight="@dimen/overlay_margin"
            android:layout_marginLeft="@dimen/overlay_margin"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="5dp"/>
    </RelativeLayout>
</RelativeLayout>

AndroidManifest:

<activity
            android:name=".Player.PlayerVLC"
            android:theme="@style/PlayerVLC"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="sensor"
            tools:ignore="InnerclassSeparator" />

样式主题:

<style name="PlayerVLC" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->

        <item name="android:statusBarColor" tools:targetApi="lollipop">@color/transparent</item>
        <item name="android:navigationBarColor" tools:targetApi="lollipop">@color/transparent</item>
        <item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
        <item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>

        <!--<item name="android:fitsSystemWindows">false</item>-->
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:progressBackgroundTint" tools:targetApi="lollipop">@color/grey400transparent</item>
        <item name="android:thumbTint" tools:targetApi="lollipop">@color/colorPrimaryDark</item>
    </style>

用于全屏显示的代码:

private void hideSystemUI() {
        // Enables regular immersive mode.
        // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
        // Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        View decorView = getWindow().getDecorView();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_IMMERSIVE
                            // Set the content to appear under the system bars so that the
                            // content doesn't resize when the system bars hide and show.
                            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            // Hide the nav bar and status bar
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN);
        }
        v.setVisibility(View.INVISIBLE);
    }

    // Shows the system bars by removing all the flags
    // except for the ones that make the content appear under the system bars.
    private void showSystemUI() {

        View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

        v.setVisibility(View.VISIBLE);


    }

我也使用了这些标志,但是在setContentView (R.layout.playervlc);之前/之后仍然无法使用。

        Window w = getWindow();
        w.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

0 个答案:

没有答案