【问题标题】:Auto rotate fullscreen video in android在android中自动旋转全屏视频
【发布时间】:2016-08-29 04:03:06
【问题描述】:

我是一个新手,我正在尝试制作一个可以从 url 播放视频的简单应用程序。我可以在我的应用中成功播放视频,但我希望它在单击按钮全屏时自动旋转、隐藏操作栏标题和全屏。

这是我的清单

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="htantruc.videotest">
    <uses-permission android:name="android.permission.INTERNET" />
       <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
        <activity android:name=".video"
            android:configChanges="orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".VideoViewActivity"
            android:configChanges="orientation|screenSize"></activity>
    </application>
</manifest>

还有我的xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".VideoViewActivity"
    android:theme="@style/CustomActivityThemeNoActionBar">
    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="250dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true">
        <com.github.rtoshiro.view.video.FullscreenVideoLayout
            android:id="@+id/videoview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />
    </FrameLayout>
</RelativeLayout>

【问题讨论】:

    标签: android fullscreen android-videoview


    【解决方案1】:
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    

    如果您不在 Activity 中,您可以通过 WINDOW_SERVICE 获得默认显示:

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    

    在引入 getSize 之前(在 API 级别 13 中),您可以使用现已弃用的 getWidth 和 getHeight 方法:

    Display display = getWindowManager().getDefaultDisplay(); 
    int width = display.getWidth();  // deprecated
    int height = display.getHeight();  // deprecated
    

    如何设置宽高

    videoView.getHolder().setFixedSize(width, height);
    

    在您的活动中调用相同的代码和onConfigurationChanged()

    【讨论】:

      【解决方案2】:

      1-尝试自动旋转 - 将这些添加到清单中:

      android:configChanges="orientation|screenSize"

      android:screenOrientation="portrait"

      【讨论】:

      • 谢谢,但这对我不起作用,我希望它在单击按钮时会旋转
      【解决方案3】:

      请实现你的全屏按钮点击如下:

       public void onFullScreenClick(View v)
       {
           getActionbar().hide();
           getActionbar().show();
      
      
           //doesn't work then try
           //getSupportActionBar().hide();
           //getSupportActionBar().show();
      
           setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
      
           // For Landscape above line and For Portrait find Below
           //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
       }
      

      注意:不要忘记添加行

      清单文件中的android:configChanges="orientation|screenSize"

      希望这会奏效

      【讨论】:

        猜你喜欢
        • 2014-07-11
        • 2012-04-26
        • 1970-01-01
        • 2013-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-09
        相关资源
        最近更新 更多