Page 1 of 1

LibVLC in a native android activity application

Posted: 09 Jun 2016 11:21
by lanamelach
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?

Re: LibVLC in a native android activity application

Posted: 28 Jun 2016 10:19
by Jean-Baptiste Kempf

Re: LibVLC in a native android activity application

Posted: 30 Jun 2016 13:59
by lanamelach
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.

Re: LibVLC in a native android activity application

Posted: 03 Jul 2016 11:57
by Jean-Baptiste Kempf
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.

Re: LibVLC in a native android activity application

Posted: 11 Aug 2016 09:54
by Andrew Forrest
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.