【问题标题】:Android VideoView resize according every deviceAndroid VideoView 根据每个设备调整大小
【发布时间】:2019-06-12 06:12:49
【问题描述】:

我正在 Android 视频视图中播放视频。问题是视频未根据设备比例调整大小。在大型设备上它被拉伸或在小型设备上它是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>

【问题讨论】:

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


    【解决方案1】:

    将整个 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-18
      相关资源
      最近更新 更多