Andreas
Andreas

Reputation: 77

how to use vlcj with java?

Hello Everyone i'm trying to use vlcj for java but am running into a lot of errors. I checked my jvm version and vlc media version both are 64 bit.

I tried a lot of codes that I had researched in the internet. I followed the step by inserting vlcj.jar in my code but nothing seems to work.

I followed the tutorial on caprica but it wouldn't work. Now i'm getting error

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

Can someone please help on this?

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();
    }

 

}

Upvotes: 0

Views: 1300

Answers (3)

Leo Bogod
Leo Bogod

Reputation: 419

Also, to do this yourself I would suggest using chrome. You just right click on whatever you want to scrape and go to inspect element. It will take you to the exact spot in the html where that element is located. In this case you first want to find out where the root of all the result listings are. When you find that, you want to specify the element, and preferably an unique attribute to search it by. In this case the root element 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();
        }
    }
    }

Upvotes: 0

nate river
nate river

Reputation: 33

install vlc media player in to same directory that your project is located

Upvotes: 2

leon
leon

Reputation: 74

Sometimes the problem is due to incompatibility of the architecture of VLC and JRE.

You can check JRE architecture using the code below:

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");

Upvotes: 0

Related Questions