B4A Library vlcb4a - a B4A wrapper of VLC (Android)

vlcb4a - a B4A wrapper of VLC (Android)

NOTE: As of August 2019, this library is not compliant with Google Play store's latest requirements which require native 64bits libs. It is still useable for apps not being distributed on Google Play Store though. If I can find my original sources and if it is not too complicated, I will try to recompile the sources in order to provide 64bit native libs. That said, things have changed over time and personally I would probably use the ExoPlayer (search the forum) these days unless you have codec-issues. Alternatively, you can use my Vitamio5 library/wrapper which has ARM64 and which is just as powerful as VLC.

This is the 2nd experimental release (Work in progress) of my library attempting to wrap VLC for Android (or parts of it) and its underlying libraries (so-files) and the most important properties/methods of VLC in order to provide a VideoView-object for B4A.

What is VLC for Android?
VLC media player is a free and open source cross-platform multimedia player that plays most multimedia files as well as discs, devices, and network streaming protocols. This is the port of VLC media player to the Android™ platform. VLC for Android can play any video and audio files, as well as network streams and DVD ISOs, like the desktop version of VLC.
VLC for Android is a full audio player, with a complete database, an equalizer and filters, playing all weird audio formats.

The official VLC Android app can be found here:
https://play.google.com/store/apps/details?id=org.videolan.vlc

As mentioned above, the vlcb4a wrapper is not the full Android VLC app but more an attempt to wrap the underlying libraries (so-files) and the most important properties/methods of VLC (its engine) to provide a VideoView-object for B4A. Apparently they are/were planning to write a VideoView-class but there has not been any development on this class for ages and all there is, is a "skeleton-class" of no use since even the related MediaPlayer-class is incomplete.

This wrapper provides its own VideoView class which I have written and compiled into the original VLC-sources based on SDK 3. The SDK can be found here: https://code.videolan.org/videolan/vlc-android/tree/master

This release (version 0.77 of June 27, 2016) adds and includes more features and also fixed some issues (see below for details). I have noted that the vlcb4a plays nearly everything I throw at it.

This is still a "Work in progress" and ETAs for new versions cannot be given. However, I think it should be OK for production by now.

In this moment, I have only compiled the so-sources for ARM but I could compile them also for other platforms such as ARM64, X86 and MIPS. Might add them later though.

The minimum SDK version is 7 (although I have not tried it if it works on such old devices).

See the second post for a current summary of methods, properties and events supported.

You can download the wrapper from here:
https://www.dropbox.com/s/i4d9bul243fc1o4/vlcb4aLIBS_v077.zip?dl=0

I also attach a sample-project (vlcdemo.zip) for B4A.

Note: use a real device
Note2: always use the VideoView object in its own activity. Within this activity, you can then add panels, subtitles and so on as usual. See sample project.

Changes in vlcb4a version 0.77 (June 27, 2016):
  • -added native subtitle support
  • -added possibility to change between 6 different video-sizes
  • -added support for selecting different audio-tracks
  • -added a MediaController (uses the standard Android one for now)
  • -added possibility to add VLC-options. You can add logging,
    OpenSL ES, audio time stretching and more. You can find many more options by googling.

  • added volume controls
  • bug fixes
Please report any bugs and/or post general feedback (negative/positive). This will help to keep me motivated and work on the library further.


Good luck!
 

Attachments

  • vlcdemo.zip
    8.8 KB · Views: 1,339
Last edited:

moster67

Expert
Licensed User
Longtime User
Can you please explain a bit better what you mean? When do you want to reload? In case the streaming is interrupted due to connection problems? If yes and if I recall correctly, then I believe the onError event should trigger..
 

Leni Berry

Active Member
Licensed User
Longtime User
Can you please explain a bit better what you mean? When do you want to reload? In case the streaming is interrupted due to connection problems? If yes and if I recall correctly, then I believe the onError event should trigger..

yes.. i mean In case the streaming is interrupted due to connection problems... so, is it ok if i call sub procedure "StartStreaming" again?
 

moster67

Expert
Licensed User
Longtime User
@Leni Berry
First, you need to try and simulate a disconnection and see the events triggered (does it start buffering?, do you see any error messages?). Unless the stream is halted completely, VLC will probably start buffering and resume streaming when it can automatically. If not, try and see if you can re-start (resume) streaming. Sometimes it also depends on the video-file and the server where the video is hosted and which might not allow resuming. You need to experiment a bit.
 

moster67

Expert
Licensed User
Longtime User
hi,
can I make a screenshot and zoom video?
Currently there is no Zoom video-mode and with this wrapper it is not possible to make screenshots.

However, with my Vitamio5 wrapper you can make screenshots. It also has a zoom video layout:
  • SetVideoLayout (VIDEO_LAYOUT As Int, AspectRatio As Float)
    Set the display options.
    Default is VIDEO_LAYOUT_SCALE or 1.
    Layout parameters: VIDEO_LAYOUT_ORIGIN or 0, VIDEO_LAYOUT_SCALE or 1, VIDEO_LAYOUT_STRETCH or 2,
    VIDEO_LAYOUT_ZOOM or 3, VIDEO_LAYOUT_FIT_PARENT or 4.
    AspectRatio - video aspect ratio, will auto detect if 0.

 
Last edited:

Almora

Active Member
Licensed User
Longtime User
Currently there is no Zoom video-mode and with this wrapper it is not possible to make screenshots.

However, with my Vitamio5 wrapper you can make screenshots. It also has a zoom video layout:
  • SetVideoLayout (VIDEO_LAYOUT As Int, AspectRatio As Float)
    Set the display options.
    Default is VIDEO_LAYOUT_SCALE or 1.
    Layout parameters: VIDEO_LAYOUT_ORIGIN or 0, VIDEO_LAYOUT_SCALE or 1, VIDEO_LAYOUT_STRETCH or 2,
    VIDEO_LAYOUT_ZOOM or 3, VIDEO_LAYOUT_FIT_PARENT or 4.
    AspectRatio - video aspect ratio, will auto detect if 0.

there is an alternative to PayPal?
I can't use paypal.
 

moster67

Expert
Licensed User
Longtime User
I guess you mean donating for Vitamio, right?
If you want you can donate using Bitcoin. Please contact me by PM if you are interested.
 

pripyat1583

New Member
Licensed User
I'm having a problem with the view disregarding the videoSize property. Also tried calling resizeVideo, which did nothing. I really need the video player to respect any size I pass it (not necessarily full-screen, as shown below), is this possible?

B4X:
videoView.Initialize("videoView")
videoView.SetVideoPath(File.Combine(usbdevices.Get(0), videoFilename))
videoView.VideoSize = 6
videoView.Start
Activity.AddView(videoView, 0, 0, Activity.Width, Activity.Height)
 

jazzzzzzz

Active Member
Licensed User
Longtime User
Am palying a live rtmp stream..In vlcb4a I got 7 sec latencywere mx player plays the same link in same device with 3 sec latency...Any way to decrease the delay? I think some sort of caching will be making this,,,I need the stream to be played in maximum liveness possible by the network setup....Any help?
 

moster67

Expert
Licensed User
Longtime User
Am palying a live rtmp stream..In vlcb4a I got 7 sec latencywere mx player plays the same link in same device with 3 sec latency...Any way to decrease the delay? I think some sort of caching will be making this,,,I need the stream to be played in maximum liveness possible by the network setup....Any help?
I don't know if there is a cache functionality in VLC. You could try the FFmpeg_b4a wrapper or an older version of Vitamio and see if there any improvements.
 

jazzzzzzz

Active Member
Licensed User
Longtime User
I don't know if there is a cach functionality in VLC. You could try the FFmpeg_b4a wrapper or an older version of Vitamio and see if there any improvements.

I tried ffmpeg but it does not shows the video at all..I tried --network-caching=0 option in vlc but that too doesnt have any effect..Vitamio is not free for testing...!
 

moster67

Expert
Licensed User
Longtime User
By googling I found some options which may work or not. Based on this SO-post, you can try to set the following values with VLCOptions:

B4X:
--file-caching=0
--network-caching=300

Remember that it must be set before calling VideoURI or SetVideoPath.
 

jazzzzzzz

Active Member
Licensed User
Longtime User

moster67

Expert
Licensed User
Longtime User
Can you confirm whether the new vitamio 5 is able to play rtsp?
It's better you ask that question in the Vitamio5 wrapper thread in order to keep this thread related to VLC.
 

jazzzzzzz

Active Member
Licensed User
Longtime User
By googling I found some options which may work or not. Based on this SO-post, you can try to set the following values with VLCOptions:

B4X:
--file-caching=0
--network-caching=300

Remember that it must be set before calling VideoURI or SetVideoPath.
I have used network caching 0 earlier and now tried your suggestion too by setting it to 300..but no change at all,...please check the code below..It does not have any effect in video..

B4X:
    VLCVideoview1.Initialize("VLCVideoview1")
    VLCMediaController1.Initialize("VLCMediaController1")
    Activity.AddView(VLCVideoview1,0, 0, 100%x, 100%y)
   
    Dim OptionList As List
    OptionList.Initialize
    OptionList.Add("--file-caching=0")
    OptionList.Add("--network-caching=300")
    OptionList.Add("--aout=opensles")
    OptionList.Add("--no-audio-time-stretch")
    OptionList.Add("-vvv")
    VLCVideoview1.SetVlcOptions(OptionList)
   
    VLCVideoview1.VideoURI = "rtmp://"&ip&":1935/live/akshayaRadio"
'    VLCVideoview1.VideoURI ="rtsp://192.168.0.122/live/0/h264.sdp"
    VLCVideoview1.RequestFocus
    VLCVideoview1.Start
 

moster67

Expert
Licensed User
Longtime User
The code looks fine to me.
Check the VLC-verbose output in your unfiltered logs and see if there are any hints why it is taking so long.
 

moster67

Expert
Licensed User
Longtime User
Nver tried it and I am not sure but the following might be worth a try - change the prefix -- into a colon :
like this:
B4X:
OptionList.Add(":file-caching=0")
OptionList.Add(":network-caching=300")

Maybe it will break the code or maybe not...
(I cannot check because I am not at home)
 

jazzzzzzz

Active Member
Licensed User
Longtime User
Nver tried it and I am not sure but the following might be worth a try - change the prefix -- into a colon :
like this:
B4X:
OptionList.Add(":file-caching=0")
OptionList.Add(":network-caching=300")

Maybe it will break the code or maybe not...
(I cannot check because I am not at home)
no change..!
 
Top