简体   繁体   English

删除Android videoview黑色栏

[英]Remove Android videoview black bar

I have a VideoView, which is rotated 90 degrees. 我有一个VideoView,它旋转了90度。 This results in an ugly black bar on the side. 这会在侧面形成一个难看的黑条。 Which would normally be under the MediaController (I think). 通常在MediaController下(我认为)。 I can't find an XML attribute to kill it and haven't found anything in VideoView documentation. 我找不到要杀死它的XML属性,也没有在VideoView文档中找到任何东西。 I'm not having any luck with Google either because I'm probably not using good search terms, as I don't know what it is. 我也没有与Google碰碰运气,因为我可能没有使用好的搜索字词,因为我不知道它是什么。 Anyone know how to get rid of this?? 有人知道如何摆脱这个吗?

My code is simple. 我的代码很简单。 I have a parent layout with a VideoView in XML, both set to match parent. 我有一个带XML的VideoView的父级布局,两者均设置为匹配父级。 Java: Java的:

this.viewer = (VideoView) findViewById(R.id.vid_view);
this.viewer.setVideoPath(Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_PICTURES) + "/Folder/" + video);
this.mc = new MediaController(this);
this.mc.setMediaPlayer(this.viewer);
this.viewer.setMediaController(this.mc);
this.viewer.requestFocus();
this.viewer.start();

格式错误的视图

The aspect ratio of a video may not match the aspect ratio of the screen, or the portion of the screen taken up by the VideoView . 视频的高宽比可能与屏幕或VideoView占用的屏幕部分的高宽比不匹配。

Your choices are: 您的选择是:

  1. Use android:gravity to position the black bar, such as centering it for a "letterbox" effect, or 使用android:gravity放置黑条,例如将其居中以实现“信箱”效果,或者

  2. Try using negative margins, so portions of the too-long dimension lie outside the screen, though this will chop off those portions of the video 尝试使用负边距,使过长尺寸的部分位于屏幕外部,尽管这会切断视频的这些部分

The latter technique works for camera previews; 后一种技术适用于相机预览。 I have not tried it with videos and VideoView . 我还没有尝试使用VideoViewVideoView It would also require some runtime calculations, unless you happen to know the aspect ratio of your videos in advance. 除非您碰巧事先知道视频的纵横比,否则还需要进行一些运行时计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM