繁体   English   中英

如何在java中使用vlcj?

[英]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 媒体播放器安装到您的项目所在的同一目录中

有时问题是由于 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");

另外,要自己做这件事,我建议使用 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();
        }
    }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM