视频的布局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>
当我获得视频视图的高度和宽度时,它会给我match_parent的宽度和高度,但不会在视频中播放视频的宽高比宽度和高度(无论视频中的视频覆盖的宽度和高度如何)。
在这里,我的代码:
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);
我的屏幕截图:
我想要在videoview中播放视频的黑色区域的宽度和高度。 但videoview的getWidth()或getMeasuredWidth()和getHeight()或getMeasuredHeight()给了我match_parent的宽度和高度。
所以,如何获得视频区域的宽度和高度(只有我们在图片中看不到整个宽度的黑暗区域)。
答案 0 :(得分:1)
尝试在 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);
}
});