如何将 vlcj 与 java 一起使用?

how to use vlcj with java?

大家好,我正在尝试将 vlcj 用于 java,但 运行 出现了很多错误。我检查了我的 jvm 版本和 vlc 媒体版本都是 64 位的。

我尝试了很多我在互联网上研究过的代码。我按照步骤在我的代码中插入 vlcj.jar 但似乎没有任何效果。

我按照 caprica 上的教程进行操作,但它不起作用。现在我收到错误

Exception in thread "main" java.lang.IllegalArgumentException: Interface (LibVlc) of library=libvlc does not extend Library B.

有人可以帮忙吗?

package mrbool.vlc.example; 

import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.factory.MediaPlayerFactory;

import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.binding.LibVlc;

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import uk.co.caprica.vlcj.binding.RuntimeUtil;
public class JavaApplication1 {
        


    public static void main(String[] args) {
      NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"C:\Program Files\VideoLAN\VLC");
      Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
      MediaPlayerFactory factory = new MediaPlayerFactory();
    }

 

}

有时是因为VLC和JRE的架构不兼容造成的

您可以使用以下代码检查 JRE 体系结构:

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


EmbeddedMediaPlayerComponent mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
        EmbeddedMediaPlayer embeddedMediaPlayer = mediaPlayerComponent.getMediaPlayer();

        Canvas videoSurface = new Canvas();
        videoSurface.setBackground(Color.black);
        videoSurface.setSize(800, 600);

        List<String> vlcArgs = new ArrayList<String>();

        vlcArgs.add("--no-plugins-cache");
        vlcArgs.add("--no-video-title-show");
        vlcArgs.add("--no-snapshot-preview");

        MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(vlcArgs.toArray(new String[vlcArgs.size()]));
        mediaPlayerFactory.setUserAgent("vlcj test player");
        embeddedMediaPlayer.setVideoSurface(mediaPlayerFactory.newVideoSurface(videoSurface));
        embeddedMediaPlayer.setPlaySubItems(true);

        final PlayerControlsPanel controlsPanel = new PlayerControlsPanel(embeddedMediaPlayer);
        PlayerVideoAdjustPanel videoAdjustPanel = new PlayerVideoAdjustPanel(embeddedMediaPlayer);

//            mediaPlayerComponent.getMediaPlayer().playMedia(Constant.PATH_ROOT + Constant.PATH_MEDIA + "tmp.mp4");
        JFrame mainFrame = new JFrame();
        mainFrame.setLayout(new BorderLayout());
        mainFrame.setBackground(Color.black);
        mainFrame.add(videoSurface, BorderLayout.CENTER);
        mainFrame.add(controlsPanel, BorderLayout.SOUTH);
        mainFrame.add(videoAdjustPanel, BorderLayout.EAST);

        //create a button which will hide the panel when clicked.
        mainFrame.pack();
        mainFrame.setVisible(true);

        embeddedMediaPlayer.playMedia("tmp.mp4");

将 vlc 媒体播放器安装到您的项目所在的同一目录中

此外,如果您自己执行此操作,我建议使用 chrome。您只需右键单击要抓取的任何内容并转到检查元素。它会将您带到 html 中该元素所在的确切位置。在这种情况下,您首先要找出所有结果列表的根所在的位置。当你找到它时,你想要指定元素,最好是一个唯一的属性来搜索它。在这种情况下,根元素 i

public class ScanWebSO 
    {
    public static void main (String args[])
    {
        Document doc;
        try{
            doc =        Jsoup.connect("https://www.google.com/search?as_q=&as_epq=%22Yorkshire+Capital%22+&as_oq=fraud+OR+allegations+OR+scam&as_eq=&as_nlo=&as_nhi=&lr=lang_en&cr=countryCA&as_qdr=all&as_sitesearch=&as_occt=any&safe=images&tbs=&as_filetype=&as_rights=").userAgent("Mozilla").ignoreHttpErrors(true).timeout(0).get();
            Elements links = doc.select("li[class=g]");
            for (Element link : links) {
                Elements titles = link.select("h3[class=r]");
                String title = titles.text();
    
                Elements bodies = link.select("span[class=st]");
                String body = bodies.text();
    
                System.out.println("Title: "+title);
                System.out.println("Body: "+body+"\n");
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }
    }