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
The following summary presents the current status of the wrapper (version 0.77 of 27/06/2016):

vlcb4a
Author:
Mikael Osterhed aka moster67
Version: 0.77
  • VLCMediaController
    Events:
    • onMediaControllerHidden
    • onMediaControllerShown
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • Hide
      Hide the controller on screen.
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • IsShowing As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • Show
      Shows the controller on screen.
      It will go away automatically after a default 3000 milliseconds of inactivity.
    • Show2 (Timeout As Int)
      Shows the controller on screen.
      It will go away automatically after 'timeout' milliseconds of inactivity.
      Use 0 to show the controller until hide() is called.
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean [read only]
    • Parent As Object [read only]
    • Tag As Object
    • Visible As Boolean
  • VLCVideoView
    Events:
    • onCompleted
    • onError
    • onPrepared
    Fields:
    • VOLUME_MUSIC As Int
    • VOLUME_VOICE_CALL As Int
    • ba As BA
    Methods:
    • BringToFront
    • CanSeekBackward As Boolean
      Verifies if the media can seek backward.
    • CanSeekForward As Boolean
      Verifies if the media can seek forward.
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • IsPlaying As Boolean
      Tests whether the video is currently playing.
    • Pause
      Pauses the playback.
    • RemoveView
    • RequestFocus As Boolean
    • Resume
      Resumes the playback.
    • SeekTo (Milliseconds As Int)
      Seeks to specified time position. Parameters: Milliseconds - the offset in milliseconds from the start to seek to.
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (Top As Int, Left As Int, Width As Int, Height As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetMediaController (MediaController1 As ExtMediaPlayerControl)
      Sets the MediaController. Video must be prepared state to set it (use onPrepared).
      To disable MediaController, set it to null.
    • SetVideoPath (VideoPath As String)
      Sets the local file path of the video to play.
      example:
      SetVideoPath(File.Combine(File.DirRootExternal, "test_video.mp4"))
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • SetVlcOptions (VlcOptions As ArrayList)
      Sets various VLC options. Must be set before calling VideoURI or SetVideoPath.
      If you don't want any options, either don't call this method or pass null as value.
      Options must be passed on in a list as strings.
      Some options that are available:
      --aout=opensles
      --audio-time-stretch 'time stretching
      -vvv 'verbosity
      example:
      Dim OptionList As List
      OptionList.Initialize
      OptionList.Add("--aout=opensles")
      OptionList.Add("--audio-time-stretch")
      VLCVideoView1.SetVlcOptions(OptionList)
    • Start
      Starts or resumes playing.
    • StopPlayback
      Stops the playback.
    • currentVideoSize As Int
      Returns current video-size.
    • getMaxVolume (channel As Int) As Int
      gets Max Volume for device and type of audio
      based on AudioManager
    • getVolume (channel As Int) As Int
      gets current Volume level
      based on AudioManager
    • resizeVideo
      Resizes the video.
    • setMute (channel As Int, state As Boolean)
      Enable or disable mute-status
      true = ON, false = off
      based on AudioManager
    • setVolume (channel As Int, level As Int)
      sets Volume level. You need to get Max volume
      first to know the range available
      Range: zero(0) to MaxVolume
      based on AudioManager
    Permissions:
    • android.permission.INTERNET
    • android.permission.WAKE_LOCK
    Properties:
    • AudioTrack As Int [write only]
      Sets selected AudioTrack.
    • AudioTrackDesc As MyMap [read only]
      Returns a description of the AudioTracks.
      Values returned are: id and name
      id is used for setting which AudioTrack to play.
      The values are available when the video is playing.
      Assign the map to a map of your own.
      example:
      Dim audiotracks As Map = VLCVideoView1.AudioTrackDesc
    • AudioTracksCount As Int [read only]
      Returns number of AudioTracks.
    • Background As Drawable
    • Color As Int [write only]
    • CurrentPosition As Long [read only]
      Returns the current playback position in units of milliseconds.
    • Duration As Long [read only]
      Returns the video duration in milliseconds.
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Parent As Object [read only]
    • Position As Long
      Gets or sets the playing position (in milliseconds).
    • SubtitleLocalSource As String [write only]
      Sets a local subtitle source (.srt).
      example:
      SetVideoPath(File.Combine(File.DirRootExternal, "sub.srt"))
    • SubtitleTrack As Int [write only]
      Sets selected SubtitleTrack.
    • SubtitlesCount As Int [read only]
      Returns number of Subtitles.
    • SubtitlesDesc As MyMap [read only]
      Returns a description of the SubtitleTracks.
      Values returned are: id and name
      id is used for setting which SubtitleTrack to show.
      The values are available when the video is playing.
      Assign the map to a map of your own.
      example:
      Dim Subtitletracks As Map = VLCVideoView1.SubtitlesDesc
    • SubtitlesSurfaceView As ViewGroup [write only]
      Takes B4A panel (ViewGroup) and adds a SurfaceView
      to use as a panel for the subtitles.
      example:
      in Globals
      Dim subpanel As Panel 'for subtitles
      in Activity_Create
      subpanel.Initialize("subpanel")
      mypanel.AddView(VLCVideoview1,0, 0, 100%x, 100%y)
      mypanel.AddView(subpanel, 0, 0, 100%x, 100%y-20dip)
      VLCVideoview1.SubtitlesSurfaceView = subpanel
      VLCVideoview1.SubtitleLocalSource = File.Combine(File.DirRootExternal,"bb.srt")
    • Tag As Object
    • Top As Int
    • VideoSize As Int [write only]
      Sets Video size. Available values are:
      SURFACE_BEST_FIT = 0, SURFACE_FIT_HORIZONTAL = 1,
      SURFACE_FIT_VERTICAL = 2, SURFACE_FILL = 3,
      SURFACE_16_9 = 4, SURFACE_4_3 = 5,
      SURFACE_ORIGINAL = 6
      Default video size is SURFACE_BEST_FIT = 0
    • VideoURI As String [write only]
      Sets the URI stream of the video to play.
      example:
      VideoURI = "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"
      VideoURI = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"
    • Visible As Boolean
    • Volume As Int [write only]
      Sets volume as integer
      This is the native volume control and is not based on AudioManager.
      This control has been reported to have problems. If you have problems
      you can use the other volume methods available based on AudioManager.
      Range should be 0-200.
      At 40 it seems to become hearable, above 100 it might cause distortion
    • Width As Int
 
Last edited:

susu

Well-Known Member
Licensed User
Longtime User
I always love video libs. Thank you Mikael.
 

DonManfred

Expert
Licensed User
Longtime User
Nine one. Thank you for sharing!
 

moster67

Expert
Licensed User
Longtime User
Thanks for the report. I will look into into when I've got a moment.
I wrote clearly that it is an "experimental beta" and "Work in Progress" in my description because in this moment it is far from being finished and probably not suitable for production. Try, as I wrote, my ffmpeg-wrapper instead until this library gets more stable.
 

moster67

Expert
Licensed User
Longtime User
Thanks, yes I guess there is work to do. Keep the bug reports coming :)

I normally add a panel and then attach the VideoView to the panel. Find it easier.

One urgent request: Please make the CurrentPosition property writeable (if possible). In my current "TV and Video" app I make my users swipe horizontally to go fast forward and fast back (skip in increments of 1 minute).

To "fast forward" the streaming, you can do something similar as this code (here I am using a panel longclick event just for testing) and vice-versa going backwards:

B4X:
Sub mypanel_LongClick
    If VLCVideoview1.CanSeekForward Then
        dim curpos as long = VLCVideoview1.CurrentPosition
        VLCVideoview1.SeekTo(curpos + 140000) '140000 is your value how much you want to fast forward
    End if

End Sub

This should work with local files. I have not tested this with remote-streaming...
Edit: now tried seeking with remote streaming and it worked (used the BigBuckBunny link)

Note that I wrote this from memory. Cannot check in this moment on a computer but it should work
 
Last edited:

moster67

Expert
Licensed User
Longtime User
vlcb4a is different from Vitamio (for which I wrote the first wrapper back in 2012). The library for Vitamio is wrapping a VideoView-class provided by Vitamio (similar to the standard VideoView-class of Android) which is well tested and for the most bug-free. The same is true for my FFmpeg-wrapper.
With vlcb4a, I am writing the underlying VideoView class myself (there is no one available for VLC) and trying to create a VideoView-object for B4A from scratch. Therefore it will surely be prone to errors (at least in this initial phase).

Some suggestions/considerations for your app:
1) I doubt if I would use vlcb4a in production just yet...
2) In this moment, I have only furnished/compiled native so-libraries for ARM and thus (your) users with devices based on other platforms such as ARM64, X86 and MIPS will not be able to install an app using vlcb4a.
3) As I said before, I am doing this on my free time and no ETA can be given and only time will tell when there will be a stable and a more feature-rich version.
 

moster67

Expert
Licensed User
Longtime User
This is better discussed in the FFmpeg-thread. However, if the problem is related to codec in the FFmpeg-wrapper, then just the build-configuration needs to be modified so new updated so-files can be compiled and replaced as explained in my first post in said thread. The wrapper-library rests in place as it is. This was made on purpose so anyone who wishes to add codecs etc can do it by their own and no one depends upon me.
 

moster67

Expert
Licensed User
Longtime User
In the FFMpeg thread you write: "You can then add the missing containers, demuxers, muxers and codec by building and recompiling the FFmpeg-libraries yourself". I have no idea how to do that. Some more guidance would be appreciated.

As I said in my previous post, this is better discussed in the FFmpeg-thread. I replied to you in that thread.
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Might be a good idea to rename "classes.jar" to something a bit less generic?
 

moster67

Expert
Licensed User
Longtime User
Might be a good idea to rename "classes.jar" to something a bit less generic?

True and a good idea. When compiling the VLC-sources, a library in the new format with an aar extension is created. By unzipping the library, I found the jar-file already named "classes.jar". I haven't investigated further if this is a standard-name within aar-libraries or if it is assigned somehow by the vlc-sources and if renaming it will have any "bad" consequences or clashes. I will check this later.
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Just tested the library, it works great. I know this is a hobby project, but two things are missing to make the video player usable.

1. The video rescales to the container's width and height. This poses a problem when you don't know the size of the video. The standard videoview passes the height and width in an event raised after you start playing a video. If you want to show a movie in the correct aspect ratio, this is a must.

2. The standard videoview also has a scrub bar that is shown underneath the video. I don't know if the VLC lib has something like that, that can be easily enabled or disabled? If it's easy to add, this is a must as well.

Thanks!
 

moster67

Expert
Licensed User
Longtime User
The wrapper is still in its "childhood" and in this case I need to write the underlying VideoView myself more or less from scratch and adjust it taking into account what is provided by the VLC MediaPlayer-class (VLC has not implemented these classes in a similar fasion to Vitamio and IJK where they were all present and which simplified the wrapping).

In due course I hope to make it behave as much as possible as the standard VideoView-library.
 

wimpie3

Well-Known Member
Licensed User
Longtime User
FYI, I have the same problem as some other users posted here when using your alternative FFMPEG library. The standard version comes without all the codecs and I can't seem to find out how to compile my own version and add more of them. Perhaps a full-blown FFMPEG with all codecs included could be a nice alternative until your VLC wrapper is ready...

In the mean time, good luck with this one!
 

moster67

Expert
Licensed User
Longtime User
Perhaps a full-blown FFMPEG with all codecs included could be a nice alternative until your VLC wrapper is ready...

I'd prefer that we stick discussing the VLC-wrapper in this thread. Anyway, as I wrote in the FFMpeg-library thread, you may contact me by PM (like others have done) if the standard FFmeg support libraries do not cover your needs and we can come to an agreement.
 

moster67

Expert
Licensed User
Longtime User
If there is someone with a device running one of the following platforms: ARM64, X86 and MIPS and who would like to help out testing vlcb4a, please contact me in PM.
Thank you.
 
Top