Android Question Video orientation within videoview

Discussion in 'Android Questions' started by Javier Alonso, Jul 10, 2015.

  1. Javier Alonso

    Javier Alonso Member Licensed User


    I am using a videoview filling the entire activity to play video, but when the video orientation (portrait or landscape) do not match the screen orientation, it plays on one side, and not centered.
    There is an obvious solution: to set the videoview position and dimensions according to the video orientation and centered in the screen, but in order to do this, i would need to know which is the video orientation. MediaBrowser is of no help, because the Resolution property is always 1920x1080 for whichever orientation (it would have helped if it said 1080x1920 when in portrait mode, but it's not the case).

    I found this method to retrieve the metadata of a video file, but I don't know how to do it in B4A, maybe using a reflector, os some library?

    Thanks in advance.
  2. Javier Alonso

    Javier Alonso Member Licensed User

    Solved, from another thread. The code (hopefully it would be self-explanatory) is:

    Dim rfl As Reflector
    Dim obj As Object

    obj = rfl.CreateObject(
    rfl.Target = obj
    "setDataSource", vidfile, "java.lang.String")
    b = rfl.RunMethod3(
    If Not(b.IsInitialized) Then
        ok = 
    File.DirAssets, "notavailable.png")
        HeightVideo    = b.Height 
        WidthVideo    = b.Width
    End If
    Where b is a bitmap and vidfile is a string containing the path to the video file. It does not work for streaming videos.
    eurojam likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice