VideoView在横屏时不适合全屏显示(使用Vitamio库)。

3
我正在使用VideoView进行流媒体播放(使用Vitamio库),问题是在横向方向下,它不能适应屏幕。
我想让我的应用程序仅限于横向。

enter image description here
这是我尝试过的方法:

MainActivity:

    public class ActivityMain extends Activity {

    private String path = "http://hw14.asset.aparat.com/aparat/video/1d7288ace5ce9cc812f6cf5b99d2b8b62642090-360p__87605.mp4";
    private VideoView mVideoView;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        if (!LibsChecker.checkVitamioLibs(this))
            return;
        setContentView(R.layout.videoview);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        mVideoView = (VideoView) findViewById(R.id.buffer);
            mVideoView.setVideoPath(path);
            mVideoView.setMediaController(new MediaController(this));
            mVideoView.requestFocus();

            mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
                    // optional need Vitamio 4.0
                    mediaPlayer.setPlaybackSpeed(1.0f);
                }
            });
    }
}

layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="#FFFFFF"
    android:gravity="center"
    android:foregroundGravity="center">

    <io.vov.vitamio.widget.CenterLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:clickable="false">

        <io.vov.vitamio.widget.VideoView
            android:id="@+id/buffer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_centerInParent="true"
            android:clickable="false" />
    </io.vov.vitamio.widget.CenterLayout>

</RelativeLayout>

清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.app">

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/MyTheme">
        <activity
            android:name="io.vov.vitamio.activity.InitActivity"
            android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|smallestScreenSize"
            android:launchMode="singleTop"
            android:theme="@android:style/Theme.NoTitleBar"
            android:windowSoftInputMode="stateAlwaysHidden" />
        <activity android:name=".ActivityMain"
            android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation"
            >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我希望视频可以像YouTube应用程序一样填满整个屏幕。
非常感谢您能提供的任何帮助。
2个回答

2
请尝试直接向WindowManager添加全屏标志。
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!LibsChecker.checkVitamioLibs(this))
        return;
    setContentView(R.layout.videoview);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    this.getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN
                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);,
    ...

欲了解更多信息,请访问http://developer.android.com/reference/android/view/Window.html

也许可以尝试以下其中一种显示选项:

 mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_ORIGIN, 0);
 mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_SCALE, 0);
 mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
 mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_ZOOM, 0);
 mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_FIT_PARENT, 0);

第二个参数表示视频的长宽比,如果为0将会自动检测。 参考此链接:https://github.com/yixia/VitamioBundle/blob/master/vitamio/src/io/vov/vitamio/widget/VideoView.java

0
最简单的选择是获取RelativeLayout并调用setSystemUiVisibility方法,将View.SYSTEM_UI_FLAG_FULLSCREEN作为标志传入。
给RelativeLayout设置Id(例如videoViewContainer),并添加以下几行代码:
setContentView(R.layout.videoview);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
RelativeLayout mVidContainer = (RelativeLayout) findViewById(R.id.videoViewContainer);
    mVidContainer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);

更多信息,请参考此链接: https://developer.android.com/training/system-ui/status.html


不工作吗? 还显示状态栏吗? 安卓 SDK 版本是多少? - Tejas Pawar
很不幸,我的意思不是想要隐藏状态栏...!问题在于VideoView无法填满整个屏幕。 - Emad
1
从附加的图像中,我可以看到视频填满了整个屏幕,除了左侧和底部边距。而您在那里写了“免费个人空间”。您能否详细解释一下问题? - Tejas Pawar
问题就在于左边和底部的边距。你说得对:D 我编辑了图片。//我正在使用Genymotion模拟器,“个人免费使用”的水印是未注册用户的标志:D - Emad
尝试将RelativeLayout的layout_width和layout_height更改为match_parent。 - Tejas Pawar
尝试将布局中所有视图的layout_width和layout_height更改为match_parent。但是,如果视频的分辨率不正确,这样会拉伸您的视频。 - Tejas Pawar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接