2

I have this code:

    public class MediaPanel {

        public static void main(final String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                     chargerLibrairie();
                     new MediaPanel(args);
                }
            });
        }
       static void chargerLibrairie(){   String ruta="C:/VideoLAN/VLC";
             NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), ruta);
            Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);

            LibXUtil.initialise();

        }

        private MediaPanel(String[] args) {
            JFrame frame = new JFrame("Tutoriel vlcj");
            frame.setLocation(100, 100);
            frame.setSize(1050, 600);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);

            //Créer une instance de Canvas
            Canvas c = new Canvas();
            //L'arrière plan de la vidéo est noir par défaut
            c.setBackground(Color.black);
            JPanel p = new JPanel();
            p.setLayout(new BorderLayout());
            //La vidéo prend toute la surface
            p.add(c, BorderLayout.CENTER);
            frame.add(p, BorderLayout.CENTER);

            //Créer une instance factory
            MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
            //Créer une instance lecteur média
            EmbeddedMediaPlayer mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
            mediaPlayer.setVideoSurface(mediaPlayerFactory.newVideoSurface(c));
            //Plein écran
            mediaPlayer.toggleFullScreen();
            //Cacher le curseur de la souris à l'intérieur de JFrame
            mediaPlayer.setEnableMouseInputHandling(false);
            //Désactiver le clavier à l'intérieur de JFrame
            mediaPlayer.setEnableKeyInputHandling(true);

            //Préparer le fichier
            mediaPlayer.prepareMedia("J.mp4");
            //lire le fichier 
            mediaPlayer.play();
        }
    }

And I have this error:

run:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Unable to load library 'libvlc': Native library (win32-x86-64/libvlc.dll) not found in resource path ([file:/C:/Users/Jes%c3%bas/Desktop/videoProyecto/jna-4.0.0.jar, file:/C:/Users/Jes%c3%bas/Desktop/videoProyecto/jna-platform-4.0.0.jar, file:/C:/Users/Jes%c3%bas/Desktop/videoProyecto/vlcj-2.4.0.jar, file:/C:/Users/Jes%c3%bas/Documents/NetBeansProjects/edicionVideo/build/classes/])

It seems that the directory is correct, but I think it doesn't load the libraries from vlc. I have ensured that the libraries are the same architecture as my pc, 64 bits, and I don't really know what the problem is.

caprica
  • 3,902
  • 4
  • 19
  • 39
  • Maybe this will help: http://stackoverflow.com/questions/8608117/vlcj-unable-to-load-library-libvlc-in-64bit-os?rq=1 – LisaMM Apr 02 '15 at 08:25
  • 1
    I've already look this link, but It didnt help me. thanks anywhere – Pablo Cacho Apr 02 '15 at 08:34
  • 2
    A few comments... 1. Don't use LibX11.initialise() on Windows. 2. Your mediaPlayer instance will go out of scope and be garbage collected some random time after your constructor exits, you must keep a reference pinned. 3. Why are you using ancient vlcj 2.4.0? Please use a newer version. 4. Are you *100% sure* that your JVM and your VLC installation are both the same CPU architecture (32bit vs 64bit). – caprica Apr 02 '15 at 18:33

2 Answers2

1

Sometimes the problem is due to incompatibility of the architecture of VLC and JRE.

You can check JRE architecture using the code below:

public class JavaApplication12 {
    public static void main(String[] args) {
        System.out.println(System.getProperty("sun.arch.data.model"));
    }
}

If VLC is 32bit then the JRE must be 32 bit too, and if VLC is 64 then JRE must be 64 too.

Tim Ferrell
  • 1,348
  • 3
  • 17
  • 40
1
cd src/main/resources/
cp -r /Applications/VLC.app/Contents/MacOS/lib darwin
rm darwin/*.*.*
cd darwin
install_name_tool -add_rpath @loader_path libvlc.dylib
mkdir vlc
cp -r /Applications/VLC.app/Contents/MacOS/plugins vlc/plugins

This is the macOS version. Worked for me. Maybe help you.

├── kotlin
│   └── App.kt
└── resources
    └── darwin
        ├── libvlc.dylib
        ├── libvlccore.dylib
        └── vlc
            └── plugins
                ├── liba52_plugin.dylib
                ├── libaccess_concat_plugin.dylib
                ├── libaccess_imem_plugin.dylib
                ├── libaccess_mms_plugin.dylib
BaiJiFeiLong
  • 3,716
  • 1
  • 30
  • 28