Android Question VideoView does not fit video size

ronovar

Active Member
Licensed User
Longtime User
I im using videoview to play video file...video is playing but is not fit to panel size it is half...how can i set viewview to fit video width and height to panel width and height size?

B4X:
'ADDVIEW - Panel
Activity.AddView(pnlVideo, 0, 0, 350dip, 180dip)

'INITIALIZE - VideoView
 VideoView1.Initialize("VideoView1")

'ADDVIEW - VideoViewRelativeLayout1
pnlVideo.AddView(VideoView1, 0, 0, pnlVideo.Width, pnlVideo.Height)
 

ronovar

Active Member
Licensed User
Longtime User
Yes i im using this library and it works fine...but first after apk is started it is in small panel pnlVIdeo...when i press OK on remote controll i need that VideoView1 is full screen, pressing again OK button need VideoView1 to be like first time in pnlVideo.

VideoViewRelativeLayout does not have SetLayout like VideoView1 so this i im missing from VideoVIewRelativeLayout.

If author of VideoVIewRelativeLayout can add this function problem will be solved:

VideoViewRelativeLayout1.SetLayout(0, 0, 100%x, 100%y)
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
ok..i im now using only VideoView1 and it works (without VideoViewRelativeLayout) but when video is 4:3 format i get 3/4 screen of picture and 1/4 is black...when video is 16:9 screen is full.

So i think i need to set in manifest editor RelativeLayout...how to set RelativeLayout in B4A Manifest editor? Then VideoView will be scalled all video aspect ratio to 16:9.

I can't use VideoViewRelativeLayout library because then i can't switch from small screen to full screen. SetLayout properties od VideoView1 is working perfectly for small screen, full screen.
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
ok..i im now using only VideoView1 and it works (without VideoViewRelativeLayout) but when video is 4:3 format i get 3/4 screen of picture and 1/4 is black...when video is 16:9 screen is full.

Sometimes it also depends on the resolution of the video-source and the resolution of the device. When it is in 4:3, why don't you center the video horizontally (and perhaps vertically) like normal TVs do. The latter I think is accepted since most TVs will show 2 black borders on the sides of the screen when displaying a video-source in 4:3 format.

If you don't like that, you need to upscale or zoom the video-source. This can probably be done with help of some inline Java code since the VideoView-class has some methods which permit changing the video-size but which are not exposed in the VideoView wrapper present in the Audio-library. When I find some time, I may extend my VideoViewPlus wrapper (see here) to include said methods.
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Thanks for info...could you post android api witch will scale video to full screen ? Then using javaobject call it will be easy to add to b4a.
Interesting is when adding relativelayout it centeres and it is full screen... this is what i need to set...relativelayout but only using videoview1 not videoview1relativelayout library (as problem described above).

http://blog.kasenlam.com/2012/02/android-how-to-stretch-video-to-fill.html
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Just had a look again at the sources and I was wrong :( I must have been confused when I wrote my earlier post considering that I have been looking at and modifying various VideoView sources in the past months when working on Vitamio, FFMpeg_B4A and VLC. Sorry about that. However, still, it should be possible to extend and add scaling-options to the original VideoView-class. When I find some time, I will have a look....

In the meantime, you can probably use the XmlLayoutBuilder library to obtain what you want.
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Thank you for replay....to me xmllayoutbuilder is unfimmiliar..and don't know how to define videoview1 to scale and add layout...could you please write here example code so that i can see how to do that.

Thanks.
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
I am sorry but I have never used it myself so I guess you will need to try and experiment a bit and see if you can obtain what you want.
If I recall correctly, another user had the same or similar requirement as you and we discussed it in the FFMpeg-B4A wrapper thread.
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Ok..i try and search for solutions and have found this interesting....for small videoview window (preview video in panel) i use this:

B4X:
Activity.AddView(VideoViewRelativeLayout1, 80%x, 20%y, 500dip, 250dip)

Above code shows preview of my video now i need to RemoveView and add anotherview:

B4X:
VideoViewRelativeLayout1.RemoveView
Activity.AddView(VideoViewRelativeLayout1, 0, 0, 100%x, 100%y)

Or more simple solution:

B4X:
VideoViewRelativeLayout1.SetLayout(0, 0, 100%x, 100%y)

If someone can write how to do SetLayout for VideoViewRelativeLayout using JavaObject or Reflector runMethod it will be great.
Aspect ratio is resized and is now correct using VideoViewRelativeLayot library but i need to when pressing OK button to switch from preview to full screen...using SetLayout will be more faster and way to go.

Any Ideas?

Or more elegant:

VideoViewRelativeLayout1.Left = 0
VideoViewRelativeLayout1.Top = 0
VideoViewRelativeLayout1.Width = 100%x
VideoViewRelativeLayout1.Height = 100%y

If author of VideoViewExtras can add Left, Top, Width And Height to his component wrapper then problem will be solved.
 
Last edited:
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Ok i found solution but need help using javaobject

B4X:
publicclassMyVideoViewextendsVideoView{@Overrideprotectedvoid onMeasure(int widthMeasureSpec,int heightMeasureSpec){int width = getDefaultSize(0, widthMeasureSpec);int height = getDefaultSize(0, heightMeasureSpec);

setMeasuredDimension(width, height);}}

So i get with and height using javaobject

B4X:
Dim jo As JavaObject=  VideoView1
Dim vvwidth As String = jo.RunMethodJO("getMeasuredWidth", Null)
Dim vvheight As String = jo.RunMethodJO("getMeasuredHeight", Null)
Log("Width..."&vvwidth&"..."&vvheight)

Now i need to call setMeasuredDimension

i try but i got error: java.lang.RuntimeException: Method: setMeasuredDimension not found in: android.widget.VideoView

So i see that this method does not exists in videoview wrapper...where i need to call this method?

i try using this code

B4X:
Dim SIze(2) As String
SIze(0) = vvwidth
SIze(1) = vvheight
Dim setscale As Int = jo.RunMethod("setMeasuredDimension", Array As Object(SIze))

Solution is at the end of this page:

http://stackoverflow.com/questions/2068242/does-android-support-scaling-video
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
I don't think you can access the method "onMeasure" because it's an @override of the original method in the super-class (SurfaceView) and I think you need that method.

What regards the method "setMeasuredDimension", it should be part of android.view.View...

It seems complicated but I may be wrong though....
Maybe it can be done with inline java?

Note: I edited my reply
 
Last edited:
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
yes you are right i read android api online documentation and there is in android.view.View setMeasuredDimension function.

If Erel or other skilled forum member can write here how to call setMeasuredDimension in android.view.View to set Width and Height using javaobject or reflector it will be great.

I have successfully read video width and height using code above, just need setMeasuredDimension function to set it up (or update it to AddView)
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Here is project code so you can try to press OK button and see small screen / fullscreen...switch between.

Load video that is 4:3 ratio and image is not full screen (on 16;9 it is full screen)

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim VideoView1 As VideoView
    Dim FullScreen As Int = 0
End Sub

Sub Activity_Create(FirstTime As Boolean)   
    'INITIALIZE - VideoView
    VideoView1.Initialize("VideoView1")
   
    'DISABLE - VideoView MediaController
    VideoView1.MediaControllerEnabled=False
   
    Activity.AddView(VideoView1, 0, 0, 500dip, 281dip)
   
    VideoView1.LoadVideo("http", "http://myurl/film.mp4")
    VideoView1.Play
End Sub

'GET - ChannelNumOSD
Sub Activity_KeyPress(KeyCode As Int) As Boolean
    Select Case KeyCode
        Case KeyCodes.KEYCODE_DPAD_CENTER
            'CHECK - FullScreen
            If (FullScreen = 0) Then
                VideoView1.SetLayout(0, 0, 100%x, 100%y)
                FullScreen = 1
            Else
                VideoView1.SetLayout(0, 0, 500dip, 281dip)
                FullScreen = 0
            End If
    End Select
End Sub

Any ide how to fix this to scale automatically 4:3 to 16:9?
 
Upvote 0
Top