videoview extension

Status
Not open for further replies.

ericvanderhoeven

Member
Licensed User
Longtime User
Guys,

I've been playing around with videos for a bit and there is one feature of the standard videoview I am not too happy with. It sticks to the default video aspect ratio of the video.

Vitamio has a nice function where you can use scaling/zooming/stretching.. Really works great! But in the end, after using it over the native videoplayer, I am not too happy with its performance.

So.... Grrr...

I then saw this post =

Kasen's Blog: Android - How to stretch video to fill VideoView area

Wow.. I would want to give that a try.

Anyone any idea how to include this into B4A? I tried adding it to the manifest and it compiles without any errors but I am not seeing any effect... Probably because I am not (yet) referencing it in my code. Would not know how to.

Thanks,

Eric
 

warwound

Expert
Licensed User
Longtime User
Hi Eric.

Here's a little library that achieves the same as that blog post.
I've named the library VideoViewExtras, it has just a single object named VideoViewRelativeLayout.
Here's the documentation:

VideoViewExtras
Version: 1.00
  • VideoViewRelativeLayout
    Methods:
    • Initialize
      Initialize the VideoViewRelativeLayout.
      VideoViewRelativeLayout is now a RelativeLayout with Width and Height both set to the Android constant MATCH_PARENT.
      (MATCH_PARENT is the same as FILL_PARENT but FILL_PARENT is now deprecated).
    • IsInitialized As Boolean
    • SetVideoView (VideoView1 As VideoView)
      Add a VideoView to the RelativeLayout.
      The VideoView Width and Height are both set to the Android constant MATCH_PARENT.
      Additionally the VideoView Layout Align is set to ALIGN_PARENT_BOTTOM, ALIGN_PARENT_LEFT, ALIGN_PARENT_RIGHT and ALIGN_PARENT_TOP.

That's all pretty self-explanatory, and here's the B4A VideoView example code modified to use the new VideoViewRelativeLayout:

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim vv As VideoView
End Sub

Sub Activity_Create(FirstTime As Boolean)

   '   http://www.b4x.com/android/help/audio.html#videoview
   '   this is the basic VideoView example modified to use ViewViewExtras and it's VideoViewRelativeLayout1 object
   
    vv.Initialize("vv")
   
   '   do not add the VideoView to the Activity
    '   Activity.AddView(vv, 10dip, 10dip, 250dip, 250dip)
   
   '   create and Initialize the VideoViewRelativeLayout1
   Dim VideoViewRelativeLayout1 As VideoViewRelativeLayout
   VideoViewRelativeLayout1.Initialize
   '   add the VideoView to the VideoViewRelativeLayout1
   VideoViewRelativeLayout1.SetVideoView(vv)
   
   '   now add the VideoViewRelativeLayout1 to the Activity
   Activity.AddView(VideoViewRelativeLayout1, 10dip, 10dip, 250dip, 250dip)
   
    vv.LoadVideo(File.DirRootExternal, "somefile.mp4")
    vv.Play
   
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Library files are attached.

Martin.
 

Attachments

  • VideoViewExtras.zip
    2.9 KB · Views: 993
Upvote 0

ericvanderhoeven

Member
Licensed User
Longtime User
videoviewextra

Mr. Warwound,

only 1 word describes this =

AWESOME

:sign0098:

Exactly what I needed to make max. use of the surface real estate :cool:

Thanks,

Eric
 
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
Is it possible to launch LoadVideo with a videofile from the assets folder inside the APK? I currently have to copy the file to DirRootExternal first, but this means users can easily find the movie on their storage space.
 
Upvote 0

deantangNYP

Active Member
Licensed User
Longtime User
Hi sir,

i was hoping to stream a video from a URL.
is this the way todo it? Thanks.
coz, was unable to play the mjpeg stream from a local network.

vv.Loadvideo("http://192.168.0.51:9090/", "http://192.168.0.51:9090/stream")


Hi Eric.

Here's a little library that achieves the same as that blog post.
I've named the library VideoViewExtras, it has just a single object named VideoViewRelativeLayout.
Here's the documentation:

VideoViewExtras
Version:
1.00
  • VideoViewRelativeLayout
    Methods:
    • Initialize
      Initialize the VideoViewRelativeLayout.
      VideoViewRelativeLayout is now a RelativeLayout with Width and Height both set to the Android constant MATCH_PARENT.
      (MATCH_PARENT is the same as FILL_PARENT but FILL_PARENT is now deprecated).
    • IsInitialized As Boolean
    • SetVideoView (VideoView1 As VideoView)
      Add a VideoView to the RelativeLayout.
      The VideoView Width and Height are both set to the Android constant MATCH_PARENT.
      Additionally the VideoView Layout Align is set to ALIGN_PARENT_BOTTOM, ALIGN_PARENT_LEFT, ALIGN_PARENT_RIGHT and ALIGN_PARENT_TOP.

That's all pretty self-explanatory, and here's the B4A VideoView example code modified to use the new VideoViewRelativeLayout:

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim vv As VideoView
End Sub

Sub Activity_Create(FirstTime As Boolean)

   '   http://www.b4x.com/android/help/audio.html#videoview
   '   this is the basic VideoView example modified to use ViewViewExtras and it's VideoViewRelativeLayout1 object
  
    vv.Initialize("vv")
  
   '   do not add the VideoView to the Activity
    '   Activity.AddView(vv, 10dip, 10dip, 250dip, 250dip)
  
   '   create and Initialize the VideoViewRelativeLayout1
   Dim VideoViewRelativeLayout1 As VideoViewRelativeLayout
   VideoViewRelativeLayout1.Initialize
   '   add the VideoView to the VideoViewRelativeLayout1
   VideoViewRelativeLayout1.SetVideoView(vv)
  
   '   now add the VideoViewRelativeLayout1 to the Activity
   Activity.AddView(VideoViewRelativeLayout1, 10dip, 10dip, 250dip, 250dip)
  
    vv.LoadVideo(File.DirRootExternal, "somefile.mp4")
    vv.Play
  
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Library files are attached.

Martin.
 
Upvote 0
Status
Not open for further replies.
Top