import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
public class MainWindow extends JFrame {
private JPanel contentPane;
EmbeddedMediaPlayerComponent playerComponent;
/**
* Launch the application.
*/
public static void main(String[] args) {
}
/**
* Create the frame.
*/
public MainWindow() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 600, 400);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JPanel videopane = new JPanel();
contentPane.add(videopane, BorderLayout.CENTER);
playerComponent = new EmbeddedMediaPlayerComponent();
videopane.add(playerComponent,BorderLayout.CENTER);
}
public EmbeddedMediaPlayer getMediaPlayer(){
return playerComponent.getMediaPlayer();
}
}
主方法
import java.awt.EventQueue;
import com.sun.jna.NativeLibrary;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import videoplayer.views.MainWindow;
public class PlayMain {
static MainWindow frame;
public static void main(String[] args) {
if(RuntimeUtil.isMac()){
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"/home/vlc");
System.out.println(LibVlc.INSTANCE.libvlc_get_version());
}else if(RuntimeUtil.isNix()){
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"/home/linux/vlc/install/lib");
System.out.println(LibVlc.INSTANCE.libvlc_get_version());
}else if(RuntimeUtil.isWindows()){
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"C:\\Program Files\\VideoLAN\\VLC");
System.out.println(LibVlc.INSTANCE.libvlc_get_version());
}
boolean found = new NativeDiscovery().discover();
System.out.println(found);
System.out.println(LibVlc.INSTANCE.libvlc_get_version());
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frame = new MainWindow();
frame.setVisible(true);
frame.getMediaPlayer().playMedia("E:\\迅雷下载\\[电影天堂http://www.dy2018.com]辛德勒的名单BD中英双字.rmvb");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
public class MainWindow extends JFrame {
private JPanel contentPane;
EmbeddedMediaPlayerComponent playerComponent;
/**
* Launch the application.
*/
public static void main(String[] args) {
}
/**
* Create the frame.
*/
public MainWindow() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 600, 400);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JPanel videopane = new JPanel();
contentPane.add(videopane, BorderLayout.CENTER);
playerComponent = new EmbeddedMediaPlayerComponent();
videopane.add(playerComponent,BorderLayout.CENTER);
}
public EmbeddedMediaPlayer getMediaPlayer(){
return playerComponent.getMediaPlayer();
}
}
主方法
import java.awt.EventQueue;
import com.sun.jna.NativeLibrary;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import videoplayer.views.MainWindow;
public class PlayMain {
static MainWindow frame;
public static void main(String[] args) {
if(RuntimeUtil.isMac()){
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"/home/vlc");
System.out.println(LibVlc.INSTANCE.libvlc_get_version());
}else if(RuntimeUtil.isNix()){
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"/home/linux/vlc/install/lib");
System.out.println(LibVlc.INSTANCE.libvlc_get_version());
}else if(RuntimeUtil.isWindows()){
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"C:\\Program Files\\VideoLAN\\VLC");
System.out.println(LibVlc.INSTANCE.libvlc_get_version());
}
boolean found = new NativeDiscovery().discover();
System.out.println(found);
System.out.println(LibVlc.INSTANCE.libvlc_get_version());
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frame = new MainWindow();
frame.setVisible(true);
frame.getMediaPlayer().playMedia("E:\\迅雷下载\\[电影天堂http://www.dy2018.com]辛德勒的名单BD中英双字.rmvb");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}