tomasbedrich
tomasbedrich

Reputation: 1370

VLCJ/libvlc crossplatform library path

I'm trying to create a cross-platform app in Java, using libvlc to play video. I've been searching the web a lot but I haven't found any code to load libvlc independently on the platform used (Mac, Win, Linux – 32 or 64 bit). I use JNA library to load libvlc.

For example, this is the code which loads libvlc from the default installation path on Mac:

NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "/Applications/VLC.app/Contents/MacOS/lib/");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);

But what if the user changes the installation path of VLC.app?!

So I need to create a path independent, cross-platform loading code. Generally I just don't know where to get the path to the folder containing the libvlc library.

Thanks for any ideas.

Upvotes: 3

Views: 5461

Answers (2)

tomasbedrich
tomasbedrich

Reputation: 1370

thanks for your help, but I found better solution. After few hours of reading of VLCJ's javadoc I noticed NativeDiscovery class, which has all these common paths already saved.

private void setupLibVLC() throws LibraryNotFoundException {

    new NativeDiscovery().discover();

    // discovery()'s method return value is WRONG on Linux
    try {
        LibVlcVersion.getVersion();
    } catch (Exception e) {
        throw new LibraryNotFoundException();
    }
}

The only con of this solution is, that if the user has installed the VLC into custom location, you are still forced to ask him, where the library is.

Upvotes: 2

MadProgrammer
MadProgrammer

Reputation: 347204

I usually search commonly know locations, such as /Applications/VLC.app/Contents/MacOS/lib/ or Program Files/VideoLan/VLC/sdk/lib.

If you can't find the libraries by searching commonly known locations, you will be forced to ask the user to provide the location for you...

I'm also using vlcj which has the ability to bundle the binaries and export/install them at runtime (this can be a little prohibitive, as it throws the size of the application out considerably)

Upvotes: 2

Related Questions