By default Android will scale the video to fit the VideoView but keeping the video aspect ratio. That means that depending on the device's screen size there might be some black spaces left around the video the video since the it's not filling the screen.
Depending on what you are looking for, you might actually want to completely fill the parent container area even if that means to stretch the video to fill the gaps (in other words, altering the aspect ratio of the video).
Well, turns out that even though the VideoView doesn't provide an explicit way to specify the filling mode, you can achieve the same result by wrapping the video view in a Relative Layout and setting the VideoView alignments to match the parent's boundaries:
<?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/videoViewRelative" 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>Here is an example of two different layouts, one using a Linear Layout to wrap a VideoView and the other one using a Relative Layout:
LinearLayour wrapper |
RelativeLayout wrapper |
So, whether you want to keep the aspect ratio of a video or stretch it to fill its parent area, using the right layout manager can get the job done.
Hope this helps!
Could you use this to make some sort of filter for google hangouts so that faces filled the screen, even if the aspect ratio and/or distance from the camera of the source feed was not ideal.
ReplyDeleteFind the face
Zoom/stretch to fill screen
Why?
To fill tablets screens with a face.
I Don't Know You, but all i can say is 'THANK YOU FOR EVER',you solved my problem
DeleteIt helps!
ReplyDeleteThank you
Many thanks! Awesome share - I've been trying to do this and couldn't get my video views to fill.
ReplyDeleteWorks a treat.
Thanks this was helpful.
ReplyDeleteYes, it helps. Thanks
ReplyDeleteI also don't want the black space but I also don't want to altering the aspect ratio. For example, for 16:9 video to be place on 4:3 screen. Normally, there is black space on the top/bottom. Then I resize the video height to screen height and keep aspect ratio such that the video width is bigger than screen width. I have implemented this in surfaceView. I can resize the surfaceView as I want but once it is bigger than the screen size, it only show black screen and keep playing audio:(
ReplyDeleteGreat, that works !!!! Thank you
ReplyDeleteI can only say u rock..............
ReplyDeleteThis is very useful post.....can u please post full video view in android emulator from local sd card codings... Thanks in advance
ReplyDeleteCool ....Thanks for sharing :-)
ReplyDeleteThank you so much.
ReplyDeleteExcellent sharing... u saved my day
ReplyDeleteThank you very much!!
Its really working,
ReplyDeletethanks.....
thank you very very much but please explain reason too..
ReplyDeleteThanx...it works...
ReplyDeletereally thanks to u ...well done...
ReplyDeleteThanks. its working great!
ReplyDeleteGreat post! Thanks A Lot .
ReplyDeleteThank you very much!
ReplyDeletethanks
ReplyDeleteJust what I needed. Thanks!
ReplyDeleteit works. Thank you!
ReplyDeleteIt really was helpful. Thank you.
ReplyDeleteThank you very much!!!!
ReplyDeleteWorks well still in 2015!
ReplyDeleteWhere do i type these commands??
ReplyDeletewhere do i write these commands?
ReplyDeletethank you! this was helpful
ReplyDeleteThanks for sharing this! Very useful~
ReplyDeleteWorking Good..Simple and correct.
ReplyDeleteWorked like a charm!!!
ReplyDeleteThanks :) This was very useful as a quick fix as opposed to overriding the videoview class
ReplyDeletereally thanx mate..
ReplyDeleteit works great thank you so much you are very helpful
ReplyDeletethanks
ReplyDeleteIt works really good and was an easy fix. Thank you!
ReplyDeleteExcellent post. Android is an open source operating system used for tablet computers and smartphones. If your are interested to develop creative mobile applications then you must learn about android OS. Its helpful for you.
ReplyDeleteRegards..
Android Training in Chennai
Simple but useful...
ReplyDeleteThanks, man! Be my guest! You deserve a piece of cake!
ReplyDeleteawesome , I dont know what I would have done if There haven't been your website
ReplyDeleteAwesome, it works great..
ReplyDeleteit doesn't work for me..
ReplyDeleteThanks a lot man
ReplyDeleteReally helpful :D
I can use this code to work,In my code ,I use fragment attach to ViewPager to show videoview,But can not stretch video to VideoView.can you help me?
ReplyDeletethanks!!
ReplyDeletethanks man , you saved my time
ReplyDeleteCheck out this article about parental control software, to stay in touch with the topic.
ReplyDeleteWorks , dude you are a genious
ReplyDeleteWorks , dude you are a genious
ReplyDeleteIts work.
ReplyDeleteThanks
Not work!
ReplyDeletenot work!
ReplyDeleteHapo sawa. Asante!
ReplyDeleteThe Info shared was very much useful My sincere thanks for sharing this post Please Continue to share this post.
ReplyDeleteAndroid Training in Chennai
Thankss !
ReplyDeleteThankss !!
ReplyDeleteThanks, Still helpful in 2018
ReplyDeleteThank you, your post saved my time.
ReplyDelete