Class MediaPlayerFactory

java.lang.Object
uk.co.caprica.vlcj.factory.MediaPlayerFactory

public class MediaPlayerFactory extends Object
Factory for creating media player instances and associated components.

When using VLC options/arguments to initialise the factory, generally any options that enable/disable modules (e.g. video/audio filters) must be set via the factory instance and not when invoking MediaApi.play(String, String...). However, the module-specific options may be able to be passed as media options and be effective via that play call.

The factory will attempt to automatically discover the location of the required LibVLC native library, so it should just work by default (at least for the most common/likely environment configurations). If you have other requirements for the native library discovery mechanism, you can pass in your own implementation of NativeDiscovery when you create the factory.

You should explicitly release() the factory when your application terminates to properly clean up native resources.

The factory also provides access to the native libvlc Logger and other resources such as the list of audio outputs, and the list of available audio and video filters.

You must make sure you keep a hard reference to the components created by this factory to prevent them from going out of scope and being garbage-collected. If you allow one of these components to go out of scope, then unpredictable behaviour will occur (such as events no longer seeming to fire) even though the video playback may continue (since that happens via native code). You will also likely suffer fatal JVM crashes.

It is always a better strategy to reuse media player instances, rather than repeatedly creating and destroying them.