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,484
Last edited:

moster67

Expert
Licensed User
Longtime User
Hard question although I think Vitamio is well-tested and probably most complete.
 

Binary01

Active Member
Licensed User
Longtime User
Thanks moster67 for your contribution.

Now I can't find setChannel (Stereo, Left, Right Channel although it includes in vlc) in vlcb4a - a B4A wrapper of VLC (Android).
 

moster67

Expert
Licensed User
Longtime User
@Binary01
where do you see that "setChannel()" is available for VLC Android. In their SDK?
 

Binary01

Active Member
Licensed User
Longtime User
@moster67

I see this feature of vlc in VLC SDK. (not in VLC Android) and use it in my QtVLC App for PC version not in android.
I have more than 5000 songs and these songs have different music channels (Stereo, Left and Right).

In VLC SDK.
Vlc::AudioChannel VlcAudio::channel() const
{
Vlc::AudioChannel channel = Vlc::AudioChannelError;
if (_vlcMediaPlayer) {
channel = Vlc::AudioChannel(libvlc_audio_get_channel(_vlcMediaPlayer));
VlcError::showErrmsg();
}

return channel;
}

void VlcAudio::setChannel(Vlc::AudioChannel channel)
{
if (_vlcMediaPlayer) {
// Don't change if channel is the same
if (channel != VlcAudio::channel()) {
libvlc_audio_set_channel(_vlcMediaPlayer, channel);
VlcError::showErrmsg();
}
}
}

kicN5Q


Thank you for your contribution.
 
Last edited:

moster67

Expert
Licensed User
Longtime User
I checked yesterday before writing my reply but I could not find this api in the Android SDK so I cannot really do anything. Sorry.
If in the future such an api will be included in the Android SDK, I will happily add it to the wrapper.
 

MAGAREY

Member
Licensed User
Longtime User
It's possible to run it on Android tv?
When i tried throws an error like this:
[INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]
 

moster67

Expert
Licensed User
Longtime User
This means you were trying to install an app that has native libraries (in this case vlcb4a) and it doesn't have a native library for your cpu architecture. For example if you compiled an app for armv7 and are trying to install it on a device that uses the Intel architecture instead it will not work.

Android TV is running on various platforms (different hardware) such as Nvida Shield but also included in Television sets. You need to find out the cpu architecture on the device you are using and see if it is compatible with ARM.

I don't know if I still have the sources for compiling the binaries for vlcb4a but I might have a look if you let me know the cpu architecture needed.
 

blong

Active Member
Licensed User
Longtime User
Perhaps overlooked something

BUT

Is there a way to get the MEDIA information from a video stream like a .ts stream

i.e. the size of the stream 1920 x 1080 or 1280 x 720 etc

I wish to open a stream and get the stream INFO

Thx in advance
 

fraenri

New Member
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.
Hi, I have released an App that use your library and I try to publicate it on Play Store, but the APK uploaded is not accepted because does not contain 64bit code.
How can I obtain ARM64 version of library?
Thanks
 

moster67

Expert
Licensed User
Longtime User
Hi, I have released an App that use your library and I try to publicate it on Play Store, but the APK uploaded is not accepted because does not contain 64bit code.
How can I obtain ARM64 version of library?
Thanks
Hi, yes you are right. This is an old library and I ought to have marked this library as not compliant with Google Play store's latest requirements. It is still useable for apps not being distributed on Google Play Store though. I will now update the first post accordingly.

I don't recall if I ever compiled ARM64 native libs for this library. I will have a look but I am not really even sure if I still have the sources. Will check and see what I can do.

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.
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Last edited:

AbdurRahman

Member
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!
@moster67
Looks like this old but powerful wrapper isn't updated for a while. This lib is huge gift for everyone using b4a.
Brother I wish if this lib uses updated vlc *.so files and I can direct feed media using bytes or stream.

Reason:
1) *.so files of 2020 have more developments, optimizations and features than of 2016. (I verify)
2) Sometimes, you have video embed as resource. So direct feed media will help me in this regard.
Thanks brother.
 

rasul.g

Member
Hi.

I tested this library (v0.77) by some video files on some devices.

It's a good library and in terms of supporting video/audio codecs works slightly better than other libraries but unfortunately, it got a very bad freeze without any error in some video formats.

for example, The player get freezes with these video files on "galaxy a20" (android 10) (no error- just app get freezes and it doesn't respond anymore)
source code and videos

also please update this library. I think it can be a very good library.
 

fathuraa

New Member
Licensed 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
i tried to add SetVlcOptions --audio-filter=scaletempo_pitch --pitch-shift=5 why error
Logger connected to: samsung SM-A705F
--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Surfaceview is null
2702
Surfaceview is null
5705
Surfaceview is null
** Activity (main) Pause, UserClosed = false **
** Service (starter) Destroy (ignored)**
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Surfaceview is null
1
main_startstreaming (java line: 640)
java.lang.IllegalStateException: can't create LibVLC instance
at org.videolan.libvlc.LibVLC.nativeNew(Native Method)
at org.videolan.libvlc.LibVLC.<init>(LibVLC.java:85)
at org.videolan.libvlc.media.VideoView.initLibVLC(VideoView.java:146)
at org.videolan.libvlc.media.VideoView.setVideoURI(VideoView.java:274)
at com.tillekesoft.vlcb4a.VideoViewWrapper.setVideoURI(VideoViewWrapper.java:238)
at b4a.examplekaraoke.main._startstreaming(main.java:640)
at b4a.examplekaraoke.main._button3_click(main.java:536)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:8160)
at android.widget.TextView.performClick(TextView.java:16222)
at android.view.View.performClickInternal(View.java:8137)
at android.view.View.access$3700(View.java:888)
at android.view.View$PerformClick.run(View.java:30236)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8653)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Surfaceview is null
1901
Surfaceview is null
1
Error occurred on line: 64 (Main)
java.lang.IllegalStateException: can't create LibVLC instance
at org.videolan.libvlc.LibVLC.nativeNew(Native Method)
at org.videolan.libvlc.LibVLC.<init>(LibVLC.java:85)
at org.videolan.libvlc.media.VideoView.initLibVLC(VideoView.java:146)
at org.videolan.libvlc.media.VideoView.setVideoURI(VideoView.java:274)
at com.tillekesoft.vlcb4a.VideoViewWrapper.setVideoURI(VideoViewWrapper.java:238)
at b4a.examplekaraoke.main._startstreaming(main.java:457)
at b4a.examplekaraoke.main._button3_click(main.java:707)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:8160)
at android.widget.TextView.performClick(TextView.java:16222)
at android.view.View.performClickInternal(View.java:8137)
at android.view.View.access$3700(View.java:888)
at android.view.View$PerformClick.run(View.java:30236)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8653)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
 
Top