LibVLC in a native android activity application

This forum is about all development around libVLC.
lanamelach
Blank Cone
Blank Cone
Posts: 31
Joined: 18 Nov 2010 13:22

LibVLC in a native android activity application

Postby lanamelach » 09 Jun 2016 11:21

There is a sample application written in Java which demonstrates the use of libvlc on android:
https://bitbucket.org/edwardcw/libvlc-a ... e/overview

I'd like to know if there is any way to do the same thing in a native android application written in C++. After building vlc according to this guide, I have got jni libs (.so files). But how do I use them? I guess, I need some headers and, probably, some other stuff. Are there any guidelines for that?
No milk today

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: LibVLC in a native android activity application

Postby Jean-Baptiste Kempf » 28 Jun 2016 10:19

Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

lanamelach
Blank Cone
Blank Cone
Posts: 31
Joined: 18 Nov 2010 13:22

Re: LibVLC in a native android activity application

Postby lanamelach » 30 Jun 2016 13:59

As far as I understand the native sample is still in java. It loads the library, written in C, passing there JNIEnv *, jaWindow and other java stuff. Is it possible to do without java? At least I'd really like to avoid java GUI and use C++/Qt (or some other framework) instead.
No milk today

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: LibVLC in a native android activity application

Postby Jean-Baptiste Kempf » 03 Jul 2016 11:57

As far as I understand the native sample is still in java. It loads the library, written in C, passing there JNIEnv *, jaWindow and other java stuff. Is it possible to do without java? At least I'd really like to avoid java GUI and use C++/Qt (or some other framework) instead.
No.
Even for native applications, you MUST have a bit in Java. The reason is that the Android C APIs do not allow the same as Java.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

Andrew Forrest
New Cone
New Cone
Posts: 1
Joined: 11 Aug 2016 09:26

Re: LibVLC in a native android activity application

Postby Andrew Forrest » 11 Aug 2016 09:54

In case you are still wondering, as mentioned, you do need the java part (and the .so files) but as long as they are packaged in the APK correctly you can still write c/c++, compile it using the NDK and run it on an Android device. I am using libvlc inside a Qt (5.5+) application which runs on Windows and Android (and will soon be done for OSX). This is an extract of the Qt .pro file which picks up the vlc bits

Code: Select all

VLC_ROOT_PATH = C:/mypathto/vlc-2.x.x VLC_SDK = sdk INCLUDEPATH += $${VLC_ROOT_PATH}/$${VLC_SDK}/include INCLUDEPATH += $${VLC_ROOT_PATH}/$${VLC_SDK}/include/vlc/plugins android { DEFINES += __MINGW32__ # this stops issues with the build thinking we are on a linux machine when we are not LIBS += $${VLC_ROOT_PATH}/android_so/libvlcjni.so } else { LIBS += -L$${VLC_ROOT_PATH} LIBS += -llibvlc -llibvlccore }
The VLC_ROOT_PATH points to a directory which is just a regular vlc installation (with some modified headers such as including vlc_interface.h in case you want to do device discovery etc). For windows, this links the vlc dll's as normal.

For Android, there is the linking to the ndk compiled libs, but also (and not visible above) is a libvlc.jar file at '$${PROJECT_ROOT}/android/libvlc.jar'. This is automatically pulled in by the Qt build system, I think because we have set ANDROID_PACKAGE_SOURCE_DIR to '$${PWD}/android'. We build our main libvlc based code in a separate library which is statically linked into the main build, and that lib also links 'libvlcjni.so'. The kicker for all of this is that we didn't want to build libvlc (although that will probably change in the future for android). To get around this, I invoked gradle (https://github.com/mrmaffen/vlc-android-sdk) to pull in precompiled libvlc bits, then extracted the .so's and the .jar file. As implied above, the headers are the same for all versions.

If it works for you, there are some pretty good open source projects for using libvlc in Qt (with varying levels of support for Android), such as https://github.com/vlc-qt/vlc-qt. We did not end up using one of these because we need to use the callbacks rather than rendering into a widget (or QML item), but if you just want video rendered in a rectangle somewhere you'll probably save some time not re-inventing the wheel.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 13 guests