Gareth Andrews
Gareth Andrews

Reputation: 55

Basic MediaPlayer gives a NoClassDefFoundError when using vlcj, NativeLibrary issue?

I'm trying to play a video in netbeans(java) using vlcj, but I get this message... i'm assuming it has something to do with the nativeLibrary but i'm unsure of what to do to make this work and i can't seem to find an answer online.

package movieplayer;

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
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 MediaPlayer extends JPanel {


    public static void main(String[] args) {
        JFrame ourframe = new JFrame();
        ourframe.setLocationRelativeTo(null);
        ourframe.setSize(720, 560);
        ourframe.setVisible(true);
        ourframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

        p.add(c);
        ourframe.add(p);

        NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:/Program Files (x86)/VLC/");
        Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);

        MediaPlayerFactory mpf = new MediaPlayerFactory();

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

        emp.toggleFullScreen();

        emp.setEnableMouseInputHandling(false);

        emp.setEnableKeyInputHandling(false);

        String file = "C:/Videos/Intro.wmv";

        emp.prepareMedia(file);
        emp.play();

    }
}

Here is the output:

run:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at uk.co.caprica.vlcj.runtime.RuntimeUtil.<clinit>(RuntimeUtil.java:35)
    at movieplayer.MediaPlayer.main(MediaPlayer.java:39)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 2 more

I followed this tutorial video: https://www.youtube.com/watch?v=XTQ1b3-TUI4

Upvotes: 0

Views: 1595

Answers (1)

Danielson
Danielson

Reputation: 2696

It says it can't find the logger Slf4j, you can download it http://www.slf4j.org/download.html

or use mvn api

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.12</version>
</dependency>

implementation

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.12</version>
</dependency>

Or gradle (can also be found on http://mvnrepository.com/ )

(note: if you don't use either of them, I recommend (as far as I know it doesn't matter which), but I find it very convenient)

Upvotes: 2

Related Questions