Search code examples
javaloadlibraryvlcj

Error problem in my code: loadLibrary cannot find symbol


package mediaplayervlcj;

import com.sun.jna.NativeLibrary;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.lang.annotation.Native;
import javax.swing.JFrame;
import javax.swing.JPanel;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.embedded.windows.Win32FullScreenStrategy;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

public class MediaPlayerVlcj {

    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setLocation(100, 100);
        f.setSize(100, 600);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);

        Canvas c = new Canvas();

        c.setBackground(Color.black);
        JPanel p = new JPanel();
        p.setLayout(new BorderLayout());
        p.add(c);
        f.add(p);  

        NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\Program Files(x86)\\VideoLAN\\VLC");
        Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
        MediaPlayerFactory mpf = new MediaPlayerFactory();

        EmbeddedMediaPlayer emp = mpf.newEmbeddedMediaPlayer(new Win32FullScreenStrategy(f));
        emp.setVideoSurface(mpf.newVideoSurface(c));

        emp.toggleFullScreen();
        emp.setEnableMouseInputHandling(false);
        emp.setEnableKeyInputHandling(false);

        String file = "loltrailer.mp4";
        emp.prepareMedia(file);
        emp.play();
    }
}

I'm having this error:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source 
code - Erroneous sym type: java.lang.annotation.Native.loadLibrary at mediaplayervlcj.MediaPlayerVlcj.main(MediaPlayerVlcj.java:47)

I'm having a problem with the loadLibrary, it says cannot find symbol...


Solution

  • You have imported the wrong Native class.

        import java.lang.annotation.Native;
    

    should be

        import com.sun.jna.Native;
    

    Moral: be careful when you used an IDE's suggested corrections / completions. They are not always correct.