gpt4 book ai didi

android - 添加视频后如何获取videoview的宽高

转载 作者:行者123 更新时间:2023-11-30 00:15:35 25 4
gpt4 key购买 nike

videoview布局xml:

   <RelativeLayout
android:id="@+id/videoEditorParent"
android:layout_width="match_parent"
android:layout_height="400dp">

<RelativeLayout
android:id="@+id/vidEditorWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@color/colorAccent">

<VideoView
android:id="@+id/vidEditor"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</RelativeLayout>

</RelativeLayout>

当我获得视频 View 的高度和宽度时,它会给我 match_parent 的宽度和高度,但不是视频 View 中正在播放的视频的宽高比宽度和高度(视频在视频 View 中覆盖的任何宽度和高度)。

这里是我的代码:

            viewWidth = vidEditor.getWidth();
viewHeight = vidEditor.getHeight();

ViewGroup.LayoutParams layoutParams = vidEditorWrapper.getLayoutParams();

dpWidthView = utilities.pxToDp(viewWidth);
dpHeightView = utilities.pxToDp(viewHeight);

dpWidthViewPerVal = (dpWidthView * 2) / 100;

layoutParams.width = viewWidth;
layoutParams.height = viewHeight;
vidEditorWrapper.setLayoutParams(layoutParams);

我的屏幕截图:

enter image description here

我想要在视频 View 中播放视频的黑色区域的宽度和高度。但是 videoview 的 getWidth() 或 getMeasuredWidth() 和 getHeight() 或 getMeasuredHeight() 给了我 match_parent 宽度和高度。

那么,我怎样才能得到视频区域的宽度和高度(只有我们在图片中可以看到的暗区,而不是全宽)覆盖在视频 View 中。

最佳答案

尝试在 OnPreparedListener 中应用您的代码例如:

    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

@Override
public void onPrepared(MediaPlayer mp) {
viewWidth = vidEditor.getWidth();
viewHeight = vidEditor.getHeight();

ViewGroup.LayoutParams layoutParams =
vidEditorWrapper.getLayoutParams();

dpWidthView = utilities.pxToDp(viewWidth);
dpHeightView = utilities.pxToDp(viewHeight);

dpWidthViewPerVal = (dpWidthView * 2) / 100;

layoutParams.width = viewWidth;
layoutParams.height = viewHeight;
vidEditorWrapper.setLayoutParams(layoutParams);
}
});

关于android - 添加视频后如何获取videoview的宽高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47363585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com