Android VideoView 根据每个设备调整大小

标签 android android-videoview android-video-player vrvideoview

我正在 Android 视频 View 中播放视频。问题是视频未根据设备比例调整大小。在大设备上它拉伸(stretch)或在小设备上它是 skeqzes。有没有办法像中心裁剪一样保持比例和填充全宽。

我检查了以下答案:

Resize video to fit the VideoView

Android VideoView orientation change with buffered video

但没有任何作用。

我的代码:

mBinding.videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {
                    @Override
                    public boolean onInfo(MediaPlayer mp, int what, int extra) {

                        if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
                            mBinding.placeholder.setVisibility(View.GONE);

                            return true;
                        }
                        return false;
                    }
                });

                mp.setLooping(true);
            }
        });

XML:

  <VideoView
            android:id="@+id/videoView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

  </VideoView>

最佳答案

将整个 xml 布局包装到 RelativeLayout 中。然后修改你的 VideoView 标签如下 -

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

    <VideoView android:id="@+id/videoView"
         android:layout_alignParentTop="true"
         android:layout_alignParentBottom="true"
         android:layout_alignParentLeft="true"
         android:layout_alignParentRight="true"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">
    </VideoView>

</RelativeLayout>

关于Android VideoView 根据每个设备调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56555686/

相关文章:

android - 4.1 工具栏中缺少向上箭头

android - 如何以编程方式删除正在进行的通知?

android - android TV 中的 videoview 屏幕变黑

android - 如何在android中获取视频的缩略图

android - 如何在 android 中执行 Ramp Slow Mo?

android - 简单 Activity 的 Xamarin Android 内存泄漏

android - SurfaceView、SurfaceTexture 和 MediaPlayer 无法在 android 中播放我的视频

android - 我如何从 wowza 服务器播放 rtsp 视频?

flutter - VideoPlayerController.network()遇到源错误

android - 将测试类/包放在一个测试套件中