简体   繁体   中英

Remove Android videoview black bar

I have a VideoView, which is rotated 90 degrees. This results in an ugly black bar on the side. Which would normally be under the MediaController (I think). I can't find an XML attribute to kill it and haven't found anything in VideoView documentation. 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. 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. 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 .

Your choices are:

  1. Use android:gravity to position the black bar, such as centering it for a "letterbox" effect, or

  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 . It would also require some runtime calculations, unless you happen to know the aspect ratio of your videos in advance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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