Class NativeDiscovery


  • public class NativeDiscovery
    extends Object
    Native library discovery component.

    This component attempts to automatically locate the LibVLC native library so that it may be reliably loaded by JNA.

    The intent is that native discovery "just works". To that end, a number of default NativeDiscoveryStrategy implementations are provided.

    It is possible to provide your own replacement native discovery strategy implementations when creating an instance of this component, or alternatively to provide none at all to sidestep automatic native discovery.

    The first discovery strategy implementation that reports that it has found the native libraries "wins" - this means that even if turns out subsequently that the native library can not be loaded via this strategy, any other remaining discovery strategies are not tried.

    It is possible that even if native discovery fails, i.e. discover() returns false, that the native library can be loaded successfully. This could happen in an environment that is already well-configured, with libraries installed in places that the Operating System and JVM already know about.

    In MediaPlayerFactory, where this native discovery component is primarily used, an attempt to load the native library will always be made, whether explicit discovery works or not.

    This behaviour is by design, as is always trying the discovery first whether or not this "default" library loading would work - since it is possible that a client application does not actually want to prioritise the default library load (e.g. different version of VLC if multiple are installed).

    • Constructor Detail

      • NativeDiscovery

        public NativeDiscovery​(NativeDiscoveryStrategy... discoveryStrategies)
        Create a native discovery component.

        If any strategies are supplied via this constructor, they entirely replace the defaults.

        Parameters:
        discoveryStrategies - zero or more native discovery strategy implementations
    • Method Detail

      • discover

        public final boolean discover()
        Perform native library discovery.

        Discovery will stop when a strategy returns a discovered location - it is still possible that the native library will fail to load, but even if does not load there is no chance to resume discovery with that strategy or any of the subsequent ones (due to how NativeLibrary.addSearchPath(String, String) works).

        If this component has already discovered the native libraries, calling this method again will have no effect.

        Returns:
      • successfulStrategy

        public final NativeDiscoveryStrategy successfulStrategy()
        Get the native discovery strategy instance that discovered the native library.

        Used only for diagnostic purposes.

        Returns:
        strategy instance
      • discoveredPath

        public final String discoveredPath()
        Get the discovered native library path.

        Used only for diagnostic purposes.

        Returns:
        native library path