Java vlcj提供错误

时间:2018-08-24 09:40:47

标签: java vlcj

我正在尝试制作一个简单的Java应用程序,该应用程序使用vlcj绑定打开媒体文件。 这些版本是: vlcj3.0.1 jna3.5.2 platform3.5.2

我正在学习一个教程,并得到以下代码:

package com.tutorial;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import sun.rmi.runtime.RuntimeUtil;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.component.DirectMediaPlayerComponent;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.player.direct.BufferFormat;
import uk.co.caprica.vlcj.player.direct.BufferFormatCallback;
import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
import uk.co.caprica.vlcj.player.direct.RenderCallback;
import uk.co.caprica.vlcj.player.direct.RenderCallbackAdapter;
import uk.co.caprica.vlcj.player.direct.format.RV32BufferFormat;

public class Tutorial {

private static final int width = 600;

private static final int height = 400;

private final JFrame frame;

private final JPanel videoSurface;

private final BufferedImage image;

private final DirectMediaPlayerComponent mediaPlayerComponent;

public static void main(final String[] args) {
    new NativeDiscovery().discover();
    NativeLibrary.addSearchPath("vlc", "/Applications/VLC.app/Contents/MacOS/lib");
    Native.loadLibrary("vlc", LibVlc.class);
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            new Tutorial(args);
        }
    });
}

public Tutorial(String[] args) {
    frame = new JFrame("Direct Media Player");
    frame.setBounds(100, 100, width, height);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    videoSurface = new VideoSurfacePanel();
    frame.setContentPane(videoSurface);
    image = GraphicsEnvironment
            .getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration()
            .createCompatibleImage(width, height);
    BufferFormatCallback bufferFormatCallback = new BufferFormatCallback() {
        @Override
        public BufferFormat getBufferFormat(int sourceWidth, int sourceHeight) {
            return new RV32BufferFormat(width, height);
        }
    };
    mediaPlayerComponent = new DirectMediaPlayerComponent(bufferFormatCallback) {
        @Override
        protected RenderCallback onGetRenderCallback() {
            return new TutorialRenderCallbackAdapter();
        }
    };
    frame.setVisible(true);
    mediaPlayerComponent.getMediaPlayer().playMedia(args[0]);
}

private class VideoSurfacePanel extends JPanel {

    private VideoSurfacePanel() {
        setBackground(Color.black);
        setOpaque(true);
        setPreferredSize(new Dimension(width, height));
        setMinimumSize(new Dimension(width, height));
        setMaximumSize(new Dimension(width, height));
    }

    @Override
    protected void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D)g;
        g2.drawImage(image, null, 0, 0);
    }
}

private class TutorialRenderCallbackAdapter extends RenderCallbackAdapter {

    private TutorialRenderCallbackAdapter() {
        super(new int[width * height]);
    }

    @Override
    protected void onDisplay(DirectMediaPlayer mediaPlayer, int[] rgbBuffer) {
        // Simply copy buffer to the image and repaint
        image.setRGB(0, 0, width, height, rgbBuffer, 0, width);
        videoSurface.repaint();
    }
}

}

我尝试了很多选项,更改了路径,但现在我想这不是问题的解决之道。

我遇到的错误如下:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Failed to initialise libvlc.

This is most often caused either by an invalid vlc option being passed when     creating a MediaPlayerFactory or by libvlc being unable to locate the required     plugins.

If libvlc is unable to locate the required plugins the instructions below may     help:

In the text below <libvlc-path> represents the name of the directory containing     "libvlc.dylib" and "libvlccore.dylib" and <plugins-path> represents the name of the     directory containing the vlc plugins...

For libvlc to function correctly the vlc plugins must be available, there are a number of different ways to achieve this:
 1. Make sure the plugins are installed in the "<libvlc-path>/vlc/plugins" directory, this should be the case with a normal vlc installation.
 2. Set the VLC_PLUGIN_PATH operating system environment variable to point to "<plugins-path>".

More information may be available in the log, specify -Dvlcj.log=DEBUG on the command-line when starting your application.


at uk.co.caprica.vlcj.player.MediaPlayerFactory.<init>(MediaPlayerFactory.java:277)
at uk.co.caprica.vlcj.player.MediaPlayerFactory.<init>(MediaPlayerFactory.java:236)
at uk.co.caprica.vlcj.component.DirectMediaPlayerComponent.onGetMediaPlayerFactory(DirectMediaPlayerComponent.java:169)
at uk.co.caprica.vlcj.component.DirectMediaPlayerComponent.<init>(DirectMediaPlayerComponent.java:103)
at com.tutorial.Tutorial$4.<init>(Tutorial.java:78)
at com.tutorial.Tutorial.<init>(Tutorial.java:78)
at com.tutorial.Tutorial$1.run(Tutorial.java:50)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:714)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

0 个答案:

没有答案