#/projects/vlcj/tutorial/full-screen
官网上有完整代码教程
注意要先调试平台对应版本64位版本的vjcj
一、工程准备
首先应该下载并安装VLC播放器,然后下载vlcj外部库。
下载slf4j中的slf4j-api-1.7.13.jar、slf4j- nop-1.7.13.jar
将vlc安装目录下的libvlc.dll、libvlccore.dll 两个文件或者plugins复制到对应的java工程目录下
以下是今天配置的图片
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.apache.log4j.Logger;
import com.sun.jna.NativeLibrary;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
public class MyVideo {
/*
* 通过查找本地路径去找到vlclib
*/
private static Logger log = Logger.getLogger("client");
public static void findLibVlc() {
boolean found = new NativeDiscovery().discover();
System.out.println(found);
System.out.println(LibVlc.INSTANCE.libvlc_get_version());
}
//设置路径
private static final String NATIVE_LIBRARY_SEARCH_PATH = "lib/vlcjlib";
public static void setLibVlc()
{
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), NATIVE_LIBRARY_SEARCH_PATH);
log.info("version:" + LibVlc.INSTANCE.libvlc_get_version());
}
public static void main(String[] args) {
//new NativeDiscovery().discover();
setLibVlc();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Tutorial();
}
});
}
}
class Tutorial {
private static Logger log = Logger.getLogger("client");
private final JFrame frame;
private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
public Tutorial() {
frame = new JFrame("My First Media Player");
frame.setBounds(100, 100, 600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
frame.setContentPane(mediaPlayerComponent);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
log.info(e+"退出");
mediaPlayerComponent.release();
System.exit(0);
}
});
log.info("play " + "1.flv");
mediaPlayerComponent.getMediaPlayer().playMedia("doc/1.flv");
}
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/bofangqi/article-121310-1.html