无法加载libvlc

时间:2014-04-05 19:26:23

标签: java jna libvlc vlcj

您好我有这段代码来播放一些视频

package video;
import javax.swing.*;

import java.awt.*;
import java.io.File;

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;

import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import uk.co.caprica.vlcj.runtime.x.LibXUtil;

/**
 * Source: Etienne Vachon
 * */
public class PlayerPanel extends JPanel {

    private File vlcInstallPath = new File("C:\\Program Files (x86)\\VideoLAN\\VLC");
    private EmbeddedMediaPlayer player;

    public PlayerPanel() {
        System.out.println(vlcInstallPath.getAbsolutePath());
        //NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcInstallPath.getAbsolutePath());
        NativeLibrary.addSearchPath(
                RuntimeUtil.getLibVlcLibraryName(), vlcInstallPath.getAbsolutePath());
        Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
        LibXUtil.initialise();
        EmbeddedMediaPlayerComponent videoCanvas = new EmbeddedMediaPlayerComponent();
        this.setLayout(new BorderLayout());
        this.add(videoCanvas, BorderLayout.CENTER);
        this.player = videoCanvas.getMediaPlayer();
    }

    public void play(String media) {
        player.prepareMedia(media);
        player.parseMedia();
        player.play();
    }
}

我的vlc是64位,我的jvm也是如此,jna,jna-platform和vlcj位于同一个文件夹lib中。但我每次都会收到此错误

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libvlc': Native library (win32-x86-64/libvlc.dll) not found in resource path ([file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/bin/, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/xmlpull_1_1_3_4c.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/xpp3-1.1.3.4.C.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/ojdbc6.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/orai18n.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/JTattoo-1.6.10.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/JFeatureLib-1.6.0-jar-with-dependencies.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/JFeatureLib-1.6.0.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/jmf.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/slf4j.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/JFeatureLib-1.6.0-sources.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/ojdbc5.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/JFeatureLib-1.6.0-javadoc.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/slf4j-simple-1.7.6.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/xuggle-xuggler-5.4.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/slf4j-api-1.7.6.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/platform-3.5.2.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/vlcj-3.0.1.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/jna-4.0.0.jar, file:/C:/Users/Shonguiz/workspace/GTI660_LAB02/lib/jna-platform-4.0.0.jar])
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:271)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
    at com.sun.jna.Library$Handler.<init>(Library.java:147)
    at com.sun.jna.Native.loadLibrary(Native.java:412)
    at com.sun.jna.Native.loadLibrary(Native.java:391)
    at video.PlayerPanel.<init>(PlayerPanel.java:29)
    at video.VideoPlayer.<init>(VideoPlayer.java:11)
    at controllerV2.MainController.<init>(MainController.java:47)
    at controllerV2.MainController.main(MainController.java:166)

在异常显示的ressources路径的ist中没有看到VLC路径,这是正常的吗?

1 个答案:

答案 0 :(得分:0)

步骤1)安装VLC X64:https://get.videolan.org/vlc/2.2.6/win64/vlc-2.2.6-win64.exe

步骤2)更改本机库路径:

File vlcInstallPath = new File("D:\\Program Files\\VideoLAN\\VLC");