Caprica Software

vlcj-pro

Introduction

The "vlcj-pro" project is a new framework that provides for so-called "out of process" media players using vlcj.

Usually, vlcj applications use an "in process" media player - i.e. the native media player is executing in the same Operating System process as the Java application. This is fine for the vast majority of use-cases, applications with a single instance of a native media player.

Some use-cases require multiple instances of a native media player in the same application. If you are lucky, this might just work with multiple in process media players. As you scale up the number of media players in the same application you are likely to start encountering fatal application crashes.

Apart from crash prevention, using out of process media players is the only way to have multiple media players in the same application with separate volume controls.


Why?

Why do these crashes occur? Well, as the number of media players increases, so does the chance for concurrent or reentrant access to LibVLC. LibVLC itself is claimed to be thread-safe and reentrant, so what's the problem?

The problem is that LibVLC itself, and the various plugins for VLC, use a myriad of different native libraries and if any one of those native libraries is not itself thread-safe and reentrant, eventually you will see "strange" behaviour and ultimately you will see fatal crashes that bring down your entire application.

A Java application simply can not trap a fatal crash in native code - your application will terminate without warning and there is nothing you can do about it.


The Solution

The only real alternative is to use "out of process" media players.

An out of process media player is a native media player that runs in its own Operating System process, rather than running in the same process as your Java application.

This means that your application and the out of process media player are independent and if the media player process crashes, the Java application will continue, and possibly recover (by creating a new media player instance to replace the crashed one).

Using out of process media players gives another major advantage over multiple in process media players - i.e. the concurrency and reentrancy problems go away because each process essentially gets its own copies of the LibVLC native libraries and the plugins.

So that sounds great, but the problem is that out of process media players are hard - at least hard to do robustly, and hard to do transparently.

The first difficulty is that it is no longer possible to simply call methods on a media player object instance, the media player is in another process - it is in fact in a different Java Virtual Machine!

Consequently some form of Remote Procedure Call (RPC) is required to comminucate a method invocation in your main application to a "remote" invocation in the external media player process.

Adding a media player event listener is also much more difficult, since the events must be sent back from the remote process to the main application by RPC as well!

Other problems include how to handle the launching and lifecycle of the external media players, how to detect crashes, how to recover, how to clean-up orphaned processes and so on.


How Does vlcj-pro Help?

vlcj-pro provides a framework to build out of process media player applications with vlcj.

vlcj-pro tries as much as possible to make the fact that you are using an out of process media player transparent. For example, with a 'normal' vlcj media player, you play the media like this:

mediaPlayer.controls().play();

With vlcj-pro, you do this:

mediaPlayer.controls().play();

Yes, it is exactly the same as far as your own application is concerned. The difference is that behind the scenes, an RPC communication is going on.

vlcj-pro also handles launching the remote player process, and notifying your application of process failures so that you may replace a broken media player with a new one.

vlcj-pro handles the initial synchronisation and the message protocol between your application and the out of process media player, and it does this transparently.

vlcj-pro delivers event listener notifications from the out of process media players as regular media player event listener notifications in the client application.

There are some limitations because of the remote nature of the out of process media players so whilst most functionality normally provided by vlcj is supported it is not possible to support absolutely everything. However, this should not impact the vast majority of applications.


Single Media Player Applications

vlcj-pro is designed primarily for applications that require multiple native media player instances.

However, single instance media player applications may still benefit from using vlcj-pro. For example, whilst it is very unlikely for a fatal JVM crash to occur with vlcj in a single player application, it is nevertheless outside the control of the application if such a crash did occur. vlcj-pro would give the same robustness and recovery benefits in a single media player application as it would in a multiple media player application.

Nevertheless, this is probably overkill for most single player media applications.


What Do I Get With vlcj-pro?

You get a Java framework to help you build out of process media player applications with vlcj.

You also get a feature-rich demo application with multiple out of process media players, also showing how to robustly handle the remote processes with a recovery strategy.


More Information

See some more technical background information is available.


How Can I Get vlcj-pro?

vlcj-pro is a commercial product.

vlcj-pro is an "add-on" product and does not include a commercial licensefor vlcj. If you want to redistribute vlcj, and you do not want to follow the terms of the GPL, you will still need a separate commercial license for vlcj.

If you do not need to redistribute vlcj, you can still use vlcj-pro internally - in this case you would need a license for vlcj-pro, but not vlcj itself.

Licensing works on the basis of use of vlcj-pro with a single named product. If you have multiple different products, you would need multiple vlcj-pro licenses, and multiple vlcj licenses as appropriate.

There are two versions of vlcj-pro:

  • the 1.x releases are stable and work with most versions of vlcj-3.x and VLC 2.2+
  • the 2.x releases are stable and and only work with latest versions of vlcj-4.x and VLC 3.x+

Note that vlcj-pro 2.x is not a drop-in replacement for vlcj-pro 1.x. While the core concepts are the same as the previous version, the API has changed in twoways - firstly, the API has been changed to incorporate all of the corresponding API changes that came with vlcj-4.x; secondly, the API used to create and manage the out of process media players has changed, the changes are minor but will require you to change code in your own applications.

Trial packages come with a full-blown demo application that shows one way that most vlcj features can be accessed in a vlcj-pro application. The demo application also shows one mechanism to deal with (and recover from) remote media player crashes.

You are free to use the same concepts as this demo application, or alternatively roll your own solution using the vlcj-pro API to deal with remote media player failures.


1.x Trial Version

At the present time there is no trial version available for download. Time-limited trial versions are sometimes made available here, please check back later. Alternatively you may contact us to request a new trial version.

User Guide

A user guide is included in the trial distribution package, but you can also view it here:


2.x Trial Version

At the present time there is no trial version available for download. Time-limited trial versions are sometimes made available here, please check back later. Alternatively you may contact us to request a new trial version.

At the present time there is no trial version available for download. Time-limited trial versions are sometimes made available here, please check back later. Alternatively you may contact us to request a new trial version.

User Guide

A user guide is included in the trial distribution package, but you can also view it here:


Interested in a Commercial License?

For more information or to request a quotation for a non-expiring commercial license, feel free to contact us.